My solution to this so far was listening to onDisappear method of an item in the ForEach and calling try? modelContext.save() manually. Autosave is not disabled and everything else works as default config.
Hope this helps :)
// Parent view
ForEach(items) { item in
ItemsGrid(item: item)
.onTapGesture {
markAsCompleted(item)
}
.modelContext(modelContext)
.onDisappear {
if (item.isDeleted) {
print("Item deleted: \(item.isDeleted)")
try? modelContext.save()
}
}
}
// In Item Detail View:
// I'm only calling this to trigger onDisappear method
private func deleteItem() {
modelContext.delete(habit)
}