ฉันสามารถทำให้รายการแฟลตที่ได้รับการสนับสนุน Core Data ทำงาน (โดยไม่มีตัวแก้ไข .listStyle) พร้อมฟังก์ชันการลบและย้าย
แต่เมื่อฉันพยายามจัดกลุ่มรายการ
}.listStyle(GroupedListStyle())
ล้อหลุดออกตามแนวคิด พารามิเตอร์ตัวแก้ไข onDelete มีลายเซ็นฟังก์ชันของ IndexSet? -> เป็นโมฆะ ดังนั้นฉันจึงไม่สามารถผ่านวัตถุที่จะลบได้
onMove โดยพื้นฐานแล้วเป็นปัญหาเดียวกัน ยกเว้นที่แย่กว่านั้น ตัวแก้ไขทั้งสองอาศัยแหล่งข้อมูลที่ถือว่าเป็นอาร์เรย์แบบแฟลตของค่าตามลำดับ ซึ่งสามารถเข้าถึงได้โดยการสมัครสมาชิก IndexSet แต่ฉันคิดไม่ออกว่าจะสร้างรายการแบบกลุ่มโดยใช้แหล่งข้อมูลแบบแฟลตได้อย่างไร
มุมมองของฉันมีลักษณะดังนี้:
//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.
}