Re: Entities without an NSManagedObjectContext?
Re: Entities without an NSManagedObjectContext?
- Subject: Re: Entities without an NSManagedObjectContext?
- From: Chris Hanson <email@hidden>
- Date: Sat, 9 Jul 2005 01:32:48 -0700
On Jul 8, 2005, at 10:09 PM, email@hidden wrote:
I would like to manipulate arrays of my NSManagedObject subclass
before selecting which ones I actually want to save to the
NSManagedObjectContext - is this possible?
Managed objects aren't "saved to" a context, they're always
associated with a context in some way. A managed object context is
part of what provides the "managed" in "managed object."
Specifically, I have a NSTableView that's bound to an
NSArrayController that's bound to the NSManagedObjectContext. I
have a second NSArrayController that I would like to load with
objects myself - based on user input and several other
computations. The user will select items from the second tableview
and elect to insert them into the first tableview. But how do I
create the objects to manipulate in the first place without them
being in the NSManagedObjectContext and thus showing up in the
first NSTableView?
You can bind your first NSArrayController's contentSet to a set that
tracks all of the "accepted" instances of your entity. You can bind
the second to a set that tracks all "non-accepted" instances. Then
prior to initiating a save, you can ask the context to delete the
instances that haven't been accepted.
Do I need two NSManagedObjectContexts? Is there a way to create
objects of my NSManagedObject subclass without attaching them to
the context?
No. You also can't move objects between contexts; you can only fetch
objects through a context or insert objects into a context. So two
contexts won't help you
I think the key point to remember is that Core Data integrates with
the rest of Cocoa, it doesn't make it obsolete. For example, you can
still use regular Foundation collections.
-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden