Re: Core Data life cycle, how to do setup that works with undo in an NSManagedObject?
Re: Core Data life cycle, how to do setup that works with undo in an NSManagedObject?
- Subject: Re: Core Data life cycle, how to do setup that works with undo in an NSManagedObject?
- From: Brian Williams <email@hidden>
- Date: Wed, 17 Jan 2007 12:46:21 -0800 (PST)
I came up with a harebrained scheme to force CD to do my bidding. I am really
not sure if this is at all a good idea. I am thinking that it's either this
approach or I figure out how to remove the extensive use of observers from my
code, it's going to be a ton of work :(
Here is the idea. For any NSMO that you want to setup observes upon creation
and deletion and have it still work with undo/redo, you setup an
NSArrayController to managed that kind of NSMO. Create a subclass of
NSArrayController and have it observe arrangedObjects on awakeFromNib. When the
AC get a notification of a change to the arrangedObjects figure out what was
added and send those a setUp message, likewise send a tearDown message to the
ones that are removed. Seems to work in my test case. You can download it here
if you are interested:
http://chromaticgray.com/UndoTest.zip
So is this completely stupid? It sure would be easier if CD had a setup message
in it's life cycle that worked with undo/redo. If there is one I can't find it.
--- Brian Williams <email@hidden> wrote:
>
> After reading all the documentation on Core Data that I can find, (BTW it
> would
> be great if there was a book covering the subject) I can't figure out the
> proper way to setup an observer in my NSManagedObject subclass. What I am
> trying to do is have one NSManagedObject observe another. So lets say I have
> a
> screen NSMO that has a relationship to a bunch of graphic NSMOs. When a
> graphic
> is moved or a property is changed I want the screen to get a notification.
>
> The documentation and the corerecipes use a commonAwake method for setup and
> override didTurnIntoFault for tear down. This is all well and good, however
> it
> doesn't work with undo. When adding a graphic to a screen in the above
> example,
> the graphic is created the common awake is called the observer is added and
> the graphic is added the screen. When you undo this actions didTurnIntoFault
> is
> called and the observer is removed. Upon redo however the commonAwake is not
> called and the observer is not re-added.
>
> How should I deal with this? Do I need to not use observers at all in my
> code?
> Is there some other setup method that I could use? Should Core Data come with
> a
> warning in big red letters "DO NOT USE OBSERVERS WITH MANAGED OBJECTS" ?
>
> Thanks in advance for any sagely advice coming my way :)
>
> Brian
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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