If you're using #SwiftData and need undo support with manually created containers (i.e. you have a schema/migrations) you need to add the undoManager manually after creating the container.

container.mainContext.undoManger = UndoManager

Then you need to use it to undo model changes with

container.undoManager?.undo()

just calling undoManager?.undo will not revert model changes.

Ask me how I know?

related: I fixed an undo bug today.

#iOSDev #macOSDev