Saya dapat membuat daftar datar yang didukung Data Inti berfungsi (tanpa pengubah .listStyle) dengan fungsi hapus dan pindah.
Tetapi ketika saya mencoba membuat daftar dikelompokkan
}.listStyle(GroupedListStyle())
roda jatuh secara konseptual. Parameter pengubah onDelete memiliki tanda tangan fungsi IndexSet? -> Batal. Jadi saya tidak bisa meneruskan objek yang akan dihapus.
onMove pada dasarnya adalah masalah yang sama, hanya saja lebih buruk. Kedua pengubah bergantung pada sumber data yang diasumsikan berupa array datar nilai berurutan yang dapat diakses oleh langganan IndexSet. Namun saya tidak dapat memikirkan cara membuat daftar yang dikelompokkan menggunakan sumber data datar.
Badan tampilan saya terlihat seperti ini:
//I'm building the list using two independent arrays. This makes onDelete impossible to implement as recommended
ForEach(folders, id: \.self) { folder in
Section(header: Text(folder.title) ) {
ForEach(self.allProjects.filter{$0.folder == folder}, id: \.self){ project in
Text(project.title)
//this modifier is where the confusion starts:
}.onDelete(perform: self.delete)
}
}
}.listStyle(GroupedListStyle())
func delete (at offsets: IndexSet) {
// ??.remove(atOffsets: offsets)
//Since I use two arrays to construct group list, I can't use generic remove at Offsets call. And I can't figure out a way to pass in the managed object.
}
func move (from source: IndexSet, to destination: Int) {
////same problem here. a grouped list has Dynamic Views produced by multiple arrays, instead of the single array the move function is looking for.
}