NSTableView and NSMutableSet

Discussion in 'Mac Programming' started by MacDonaldsd, Dec 22, 2007.

  1. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #1
    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.
     

    Attached Files:

  2. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #2
    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.
     
  3. MacDonaldsd thread starter macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #3
    Ok I fixed it by filtering the NSArrayController itself
     

    Attached Files:

Share This Page