Hi there, I have an application that uses Core Data that has a relationship that I would like to group by. I have NSManagedObject classes that were generated by my .xcdatamodel file, and everything seems to be working OK for the most part.
Given a parent / child relationship, I would like to do the following:
A parent has a collection of children. The children have a property, groupByProperty, that I would like to group on.
The following code:
NSSet *allChildren = parent.children;
NSArray *groups = [allChildren valueForKeyPath:@"@distinctUnionOfObjects.groupByProperty"];
Child *child = [groups objectAtIndex:x]; //x is the row that I would like to retrieve
produces an NSInvalidArgumentException when trying to set the child pointer.
However, when I do this:
NSSet *allChildren = parent.children;
NSArray *groups = [[NSArray alloc] initWithArray:[allChildren valueForKeyPath:@"@distinctUnionOfObjects.groupByProperty"]];
Child *child = [groups objectAtIndex:x]; //x is the row that I would like to retrieve
everything works fine.
Can anyone explain this behavior? I'm going nuts trying to figure out how this works.
Thanks in advance for any help you can provide...
Chris