My Mac application is setup to always do changes to its models off the main thread as follows:
- make changes in a separate thread (with its own context)
- save in the background, which pushes changes to the parent context in the main thread
- post a notification to trigger UI updates
- thread exits
This works very well, but now I want to enable undo for the changes I make. How do I go about this? I only see two equally-bad options:
- I keep the child contexts and hence its undo managers around in case the user wants to undo. This will limit the number of undos I can make though because it seems weird to manually keep a stack of contexts lying around for the sake of undo.
- Alternatively, can I set the child contexts' undo managers to be the parent context's undo manager? so that there will always only be one undo manager in the application. This also sounds wrong because of how managed objects are not supposed to be shared across different threads.
Does anyone have any ideas?
Thanks.