do {
let container = try ModelContainer(for: schema, configurations: [modelConfiguration])
container.mainContext.undoManager = UndoManager()
return container
} catch { fatalError("Could not create ModelContainer: (error)") }
when you need to undo
@Environment(\.modelContext) var modelContext
modelContext.undoManager?.undo()
Post
Replies
Boosts
Views
Activity
do {
let container = try ModelContainer(for: schema, configurations: [modelConfiguration])
container.mainContext.undoManager = UndoManager()
return container
} catch {
fatalError("Could not create ModelContainer: (error)")
}
same question , use container.mainContext.autosaveEnabled = false didn't work for me