On 2011-01-22, at 6:55 AM, Kenneth Baxter wrote: > I thought I would try to do the necessary pre and post-processing using the > -willChangeValueForKey:withSetMutation:usingObjects: and > -didChangeValueForKey:withSetMutation:usingObjects: methods, and sure enough > they get called at the right times, and work just fine for undo, but then > when I redo, my Node objects come back as blank empty objects instead of > being populated with my data. > > Any ideas why this would be?
From the docs for willChangeValueForKey:withSetMutation:usingObjects: "You must not override this method." The Overview for the NSManagedObject class in the docs describes what you can override. > > Essentially the flow is: > 1. Create the child, which populates a bunch of things in the awakeFromInsert > using primitive set methods. > 2. Make some other changes to the object > 3. Add it to the children (which triggers my post-processing) > 4. Make some more changes to the object > (end of action) > Undo, which removes the child and triggers my pre and post processing to > remove related items This is the part that doesn't make sense to me. While you certainly have to worry about making sure your view is in sync with you data model, you should not have to update the nodes in your data model. Core data will do that for you on undo and redo. To keep your view in sync, if you put a controller object between it and the data model, then the controller has to worry about when to stop observing the managed object, not your view (and the NS*Controller classes do this). Now your view just has to change state when it observes that the data has changed or gone away. It may be more efficient if the view simply notes that a change has occurred in observeValueForKeyPath:ofObject:change:context:, and then coalesces all updates in one place such as drawRect: (since observeValueForKeyPath: may get hit several times during the update of a single object). Your view seems to follow all the intermediate changes of the data model within a single event cycle. That seems a bit fragile to me. > Redo, which knows that there is an object to reinsert, but it has nothing > populated - not even my initial values that were set originally in > awakeFromInsert. > > Surely the data should be populated in the object by this stage? I tried > willAccessValueForKey:nil in case it was a fault, and checked isFault and > isDeleted, but nothing helped. > > Thanks > > Ken_______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/dave.fernandes%40utoronto.ca > > This email sent to dave.fernan...@utoronto.ca _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com