re: Core Data for managing subtree?
re: Core Data for managing subtree?
- Subject: re: Core Data for managing subtree?
- From: Ben Trumbull <email@hidden>
- Date: Sun, 13 Apr 2008 15:54:04 -0700
At 6:13 PM -0700 4/8/08, email@hidden wrote:
However, I would like to use Core Data to manage these items. I figure
I could have my add and remove methods insert and remove objects from
the managed object context as well as the KVO-compliant mutable array,
but when I undo such an action, the change will only be reflected in
the managed object context. I could create an extra entity to act as a
collection for those items and have the add and remove methods
manipulate that object, but I don't see how this collection could then
be KVO-related to its parent node as per mutableArrayValueForKey:.
Hamish,
The easiest way to get array and tree controllers to work with Core
Data results is to put them into Entity mode. If you want to bind to
a to-many relationship keypath, you can bind to their 'contentSet'.
Core Data to-many relationships respond to mutableSetValueForKey:
If you only want only some of the tree using Core Data objects, you
could try having an array controller manage the extra entity, and
wire its content into your tree controller. You don't need a to-many
relationship for that. The array controller in entity mode directly
observes the NSManagedObjectContext with which it is associated.
If you want to customize things even further, you can observe the
NSManagedObjectContext's
NSManagedObjectContextObjectsDidChangeNotification yourself, and
update your custom controllers based on the contents of that
NSNotification. The array controller in entity mode is basically
doing this, plus observing some of the managed object properties
directly with KVO.
--
-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