Unlike the Hacking with Swift article, I set my undo manager from the environment and it works. The only catch you can't do in the app context, it has to be on a view level. In any content view, we can access undo manager through the @Environment(\.undoManager) var undoManager, then when I create my content view I initiate the background task using the .task modifier, and setting the under manager: modelContext.undoManager = undoManager. It's probably not a best practice though.
Post
Replies
Boosts
Views
Activity
A hackingwithswift article suggests creating a new UndoManager for the shared container. However, this technique doesn't work for me and Undo/Redo commands are greyed out in my test app.
container = try ModelContainer(for: Store.self, Book.self)
container.mainContext.undoManager = UndoManager()
Thanks. I have replied with the information. Also filed feedback with sample project. FB13204465
Clarification, 1 and 2 are .watchkitapp and .watchkitapp.widget.
Minor annoyance, I still don't see the widget on the Simulator but it shows in the Smart Stack on my Apple Watch.