views:

135

answers:

1

In a portion of a program I'm working on, I need to count all the times each person has worked on projects with each other person. Let's say we have "Employee" entities and "Session" entities. In each session, there are four project types, "A", "B", "C", & "D", each a many-to-many relationship to Employees.

I'm making a loop to systematically review every person a selected person has worked with. First, I put all their project types in a single array, so it's easier to loop through, but by the time I ask the last nested Project for its Employee members, I get an "unrecognized selector" error.

IBOutlet NSArrayController * superList;

EDIT: I forgot to represent this array that points to the controller's arrangedObjects.

NSArray * list = [superList arrangedObjects];
int x;
for(x = 0; x < [list count]; x++){
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectAs"];
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectBs"];
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectCs"];
NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectDs"];

NSArray *masterList = [[NSArray alloc] initWithObjects: projectAs, projectBs, projectCs, projectDs, nil];

int y;
for(y = 0; y < [masterList count]; y++){
int z;
for(z = 0; z < [[masterlist objectAtIndex:y] count]; z++){
//And now to make an Array of this employee's partners on the selected object, to run comparisons on.
//I also have an array of keys for each session's teams, so that's what I'm referencing here:
NSArray * thisTeam = [list objectAtIndex:y] objectAtIndex:z] valueForKey:projectKey];

This throws an exception... namely, -[_NSFaultingMutableSet objectAtIndex:]: unrecognized selector sent to instance

What's wrong with that last Array creation?

+1  A: 

Based on your line:

NSArray *A = [[list objectAtIndex:x] valueForKey:@"projectAs"];

The call:

[list objectAtIndex:y]

does not return an array - it returns a NSDictionary, which means you cannot call objectAtIndex:z on the result.

It appears this should be [masterlist objectAtIndex:y] ?

ericgorr
You were dead on, but I just realized I misrepresented my code. "list" was supposed to be an array pointing to the AC's arrangedObjects, not the AC itself. See a problem left?
DanF
Try this:id whatAmI = [list objectAtIndex:y];NSLog( @"%@", whatAmI" );NSArray* thisTeam = [[whatAmI objectAtIndex:z] valueForKey:projectKey];At this point, we need to know exactly what [list objectAtIndex:y] is returning.
ericgorr
So I think the problem is, I'm not sure what kind of object is retrieved when I query an Employee (or "Player") what their valueForKey:@"redTeams" is. I'm hoping for an array or set of the to-many instances this should recall, but when I did the id-NSLog test, it calls the key's result:Relationship objects for {( <NSManagedObject: 0x100e7e880> (entity: Show; id: 0x100e75500 <x-coredata://127334FE-4C65-4474-935C-40426C1AEEBC/Show/p5> ; data:Which seems to be a single object, not a set or Array.
DanF
Ok, well, as you have noted, a NSManagedObject does not recognize -objectAtIndex:, so, hence, your error. Unfortunately, I don't have enough experience at this point with Core Data to provide much additional help. However, it would seem to me that the data you are seeking is stored within the NSManagedObject and that you will need to use -valueForKey: to extract it. You just need to determine what that key might be. I would suggest reviewing how you set up your Core Data objects.
ericgorr