Re: How to synchronize my MacOS-X application with Core-Data automatic Undo management?
Re: How to synchronize my MacOS-X application with Core-Data automatic Undo management?
- Subject: Re: How to synchronize my MacOS-X application with Core-Data automatic Undo management?
- From: Keary Suska <email@hidden>
- Date: Sun, 24 Aug 2014 14:38:03 -0600
On Aug 24, 2014, at 9:07 AM, Motti Shneor <email@hidden> wrote:
> My OS-X app is using ARC, is CoreData Document-Based (using the old NSPersistentDocument) and uses 10.9 SDK.
>
> Up until now, I did nothing on my behalf to support user Undo/Redo, still the application seemed to work fine. I was very impressed with Cocoa (this millionth time).
>
> However. In some of my application controller objects, I maintain and rely on references to CoreData entities (NSManagedObject instances) for the application state (The current entity I'm working on, etc.)
>
> When user selects "Undo" (or cmd-Z) - my controllers lose track of the application state. Last created entities get deleted by Core-Data, and my references point to dead entities. In short - I lose synchronization with my model.
>
> If I set those entity references to "strong" then the NSManagedObjects can't be released of course, but I'll soon crash because they were deleted from CoreData. If I make them weak references insted, they will nullify upon undo --- but no one will ever set these references to their previous values (the older state).
>
> It seems I need to add my own "undo actions" to the automatic mechanism, but I don't know WHEN is the right time to do it, WHAT undo-managed I should address, and HOW to group my "undo" and "redo" actions, with the CoreData's undo actions.
>
> I tried to dive into the Undo architecture documentation, but got confused very soon, especially because CoreData does its thing independently of other parts of my program.
>
> Any hint or sample-code reference, or clarifying note will be greatly appreciated!
There is not likely a single solution to what you are after. AFAIK, there is no reliable way to track what the managed object context is doing vis a vis undo. You can, however, decide whether undo can happen, to what undo manager object undos will be registered and whether they are registered at all. You can also watch for the NSManagedObjectContextObjectsDidChangeNotification notification, and query the objects to see if it effects your controller's states. You can also use multiple managed object contexts with different undo managers, and reconcile them later. What you specifically need to do will determine the best approach.
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden