I'm working on a SwiftUI macOS app that uses Core Data. I'd like to take advantage of Core Data's built-in undo functionality, but I'm having a hard time figuring out how to assign the environment's undoManager to my Core Data's ManagedObjectContext's undoManager property. I've tried assigning from the moc to the .undoManager environmentKey, but that's read-only. If I try to assign it to the moc in the ContentView's view's .onAppear(), the undoManager value in the environment is returning nil (I guess it comes and goes as it pleases from what I can surmise in the documentation?).
Any advice or links to articles/documentation for the correct pattern to have my moc's undoManager referencing the same object as my SwiftUI's environment would be greatly appreciated. I've been searching for a while and haven't had much luck.
I have a work-in-progress test app on GitHub if anyone wants to take a look.
Any advice or links to articles/documentation for the correct pattern to have my moc's undoManager referencing the same object as my SwiftUI's environment would be greatly appreciated. I've been searching for a while and haven't had much luck.
I have a work-in-progress test app on GitHub if anyone wants to take a look.
Last edited: