The snippit of code I was using turned out to be working correctly. The problem was when I was displaying the data in a UITableView
it was correctly graping the number of entities in the NSSet
thus showing the correct number of cells. However, I had an code:
NSSet *entitiesSet = [self.selectedEntity1 valueForKey:@"entity2"];
NSArray *entities = [entitiesSet allObjects];
Entity2 *entity = [entities objectAtIndex:[indexPath indexAtPosition:0]];
This cause the cell to only display the last object in the NSSet
causing it to look like duplicates. I fixed the problem by changing the 0
to a 1
like this:
Entity2 *entity = [entities objectAtIndex:[indexPath indexAtPosition:1]];