Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MacDonaldsd

macrumors 65816
Original poster
Sep 8, 2005
1,005
0
London , UK
Hi im having a little problem with displaying a many to many relationship in core data.

Basically when I select a Event I can add a person to the event using the code

Code:
-(IBAction)addRelationShip:sender{
	
	NSLog(@"Attempting to create a relationship");
	
	NSArray *peoples=[allPeople selectedObjects];
	People *person=[peoples objectAtIndex:0];

	NSArray *events=[allEvents selectedObjects];
	Event *event=[events objectAtIndex:0];
	
	NSMutableSet *eventSet = [person mutableSetValueForKey: 
							   @"events"];
	[eventSet addObject:event];
	
	[person setValue:eventSet forKey:@"events"];
	
	
	
}

And I can print out the number of people related to then event (shown in NSLog) so I assume the above code is working.

The problem is I wish to show the people for each event in the table on the bottom left. As each "Person" returns a NSMutable set it isn't working.

I feel Im missing something blatantly obvious but can't put my finger on it.
 

Attachments

  • Example Picture.png
    Example Picture.png
    137.2 KB · Views: 133

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
mutableSetValueForKey: has always caused problems with CoreData, involving destroying the data. I create an NSMutableSet first and then set it with valueForKey:.

Although I preach about Bug Reports I haven't filed one on this.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.