Re: CoreData Predicate Question - Retriving child objects
Re: CoreData Predicate Question - Retriving child objects
- Subject: Re: CoreData Predicate Question - Retriving child objects
- From: Conor <email@hidden>
- Date: Fri, 08 Feb 2008 10:27:24 +0100
There are several options, I modified the NSManagedObject that the
NSOutlineView in bound to. I have collections that have entries in them, so
I subclassed the entries getter to add the children if necessary:
- (NSMutableSet *)entries
{
[self willAccessValueForKey: @"children"];
NSMutableSet *children = [self primitiveValueForKey: @"children"];
[self didAccessValueForKey: @"children"];
if ([children count]) {
NSMutableSet *unionSets = [NSMutableSet set];
NSEnumerator *childrenEnum = [children objectEnumerator];
MOCollection *nextCollection;
while (nextCollection = [childrenEnum nextObject]) {
NSMutableSet *tmpEntries = [nextCollection
valueForKey:@"entries"];
[unionSets unionSet:tmpEntries];
}
return unionSets;
}
else {
[self willAccessValueForKey: @"entries"];
NSMutableSet *tmpEntries = [self primitiveValueForKey: @"entries"];
[self didAccessValueForKey: @"entries"];
return tmpEntries;
}
}
You will have to modify this a bit as in this example the collection with
children have no entries of their own, only the children have entries. Move
the unionSets variable out into the function and remove the else statement
and have the entries for the current object also added to the unionSets and
return the unionSet, instead of doing one or the other.
Regards,
Conor
http://www.bruji.com/
_______________________________________________
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