Post

Replies

Boosts

Views

Activity

Proper way of using sheets in lists
Is it bad practice if I put sheet elements inside the ItemCell? Or do they have to be placed outside of the ForEach? Pseudo: ItemCell { @ObservedObject var item Text(item.description) .confirmationDialog <-- Present delete confirmation .swipeActions .contextMenu .sheet(...) <-- Present edit form .sheet(...) } List { Section { ForEach(pinned) {item in ItemCell(item: item) } } header: { Text("Pinned items") } Section { ForEach(notPinned) {item in ItemCell(item: item) } } }
0
2
425
Nov ’22
How to implement multiple selection types in NavigationSplitView?
In the sidebar column of the NavigationSplitView I'd like to have several sections. All the items are fetched with Core Data. View all photos (Photos entity in Core Data) Folder (Folder entity in Core Data) Folder A Folder B Folder C Tags (Tag entity in Core Data) Cat Dog In the content view, I'd like show the items based on the selection in the sidebar. I tried the following with some success but I think there should be another way of doing this. NavigationSplitView() { List(selection: $navigationModel.selectedCategory, content: { NavigationLink(value: Category(type: .all, predicate: NSPredicate(value: true), title: "View all items") ) {                     Text("View all items")                 }   Section { ForEach(folders){ folder in NavigationLink(value: Category(type: .folder, predicate: NSPredicate(format: "folder == %@", folder), title: folder.name) ) { FolderRow(folder: folder) // ... and so on. Another section for tags And in the content: ZStack{ List(selection: $navigationModel.selectedPhoto) {     ContentView(photos: FetchRequest(                   sortDescriptors: [sortDescriptor], predicate: navigationModel.selectedCategory?.predicate,                   animation: .default) //.... How can refractor this code with a better solution? The problem that I'm encountering is that the selection argument in the List accepts only one type of object. But I want to select more that one type of object. Another issue is that this solution won't conform to Codable if I'm thinking correctly and reseting the app state on the next launch would be cumbersome.
2
0
783
Oct ’22