Re: Creating a managed object without adding it to the context?
Re: Creating a managed object without adding it to the context?
- Subject: Re: Creating a managed object without adding it to the context?
- From: Ben Trumbull <email@hidden>
- Date: Sat, 24 Jan 2009 15:18:57 -0800
On 2009 Jan 24, at 14:13, Ulai Beekam wrote:
How do I programmatically create a managed object (with respect to
some entity in a particular context of course) but WITHOUT adding it
to the context?
I do not believe this is possible. A managed object without a context
would not be "managed".
The second does not imply the first. You can simply pass in nil to
the designated initializer. The object will not be managed. No
saving, no undo, no MOC notifications, etc. The biggest issue is that
without a MOC, no one is observing relationship changes, so it's
trivially easy to corrupt an object graph by failing to maintain
inverses by hand.
In theory, if an entity had no relationships this would work fine.
The reason I want this is to be able to take that new managed object
and add it via an NSArrayController (one that is connected to said
context of course) instead. That way I will get all the benefits of
the array controller, such as the newly inserted object getting
selected in a table view that is bound to the array controller.
You indicated in your first sentence that you know which managed
object context the new object is destined for. I don't see the
problem. Just insert it when you create it.
You can simply call -insertObject on the MOC with the new MO when you
are ready. However, any changes you make to the object between the
time of +alloc and -insertObject: will be unobserved. All the same
issues about using -awakeFromInsert instead of -initWithEntity:... to
perform initializations on modeled properties apply here.
- Ben
_______________________________________________
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