ould the below be the most appropriate way to handle updating the orderNum of items in a List when the manual order is stored in core data (as the orderNum field).
Specifically I note when I try to cycle through my fetchedResults list after I have deleted an item, that item is in fact still there. So what I'm doing is doing a core data save, and then after this updating the orderNum and then resaving. OK approach?
Key code sections:
@Environment(\.managedObjectContext) var context
@FetchRequest(fetchRequest: GCList.allListFetchRequest()) var gcLists: FetchedResults
private func save() {
// Save
do {
try self.context.save()
} catch let e as NSError {
print("ERROR : \(e.description)")
}
}
private func deleteList(at offsets: IndexSet) {
// Remove Items
for index in offsets {
let list = self.gcLists[index]
self.context.delete(list)
}
self.save()
// Redo orderNum *** NEED TO DO ANOTHER UPDATE/RESAVE LIKE THIS ***
var i = 0
self.gcLists.forEach { gcItem in
gcItem.orderNum = Int64(i)
i += 1
}
self.save()
}