I am trying to replace objects in a many to one ordered CoreData relationship... My code is here:
NSMutableOrderedSet *battingLineUpTemp = [battingOrderToChange.battingOrder mutableCopy];
NSUInteger newBatsmanIndex = 0;
NSLog(@"Original batting order");
for (CricketPlayer *p in battingLineUpTemp) {
NSLog(@"switching : %@ %@",p.firstName, p.lastName);
}
for (int i = [innings.wicketsFallen integerValue] +2; i < [battingOrderToChange.battingOrder count]; i++) {
//[battingLineUpTemp replaceObjectAtIndex:i withObject:batsmenArray[newBatsmanIndex]];
[battingLineUpTemp replaceObjectAtIndex:i withObject:[batsmenArray objectAtIndex:newBatsmanIndex]];
newBatsmanIndex++;
}
NSLog(@"Changed batting order");
for (CricketPlayer *p in battingLineUpTemp) {
NSLog(@"switching : %@ %@",p.firstName, p.lastName);
}
[battingOrderToChange willChangeValueForKey:@"battingOrder"];
[battingOrderToChange setBattingOrder:[[NSOrderedSet alloc] initWithOrderedSet:[battingLineUpTemp copy]]];
battingOrderToChange.battingOrder = battingLineUpTemp;
[battingOrderToChange didChangeValueForKey:@"battingOrder"];
Yet the second time i output the players names I get the exact same result as beforehand! I have made sure that the NSArray (batsmenArray) which I'm passing to the method is not in the same order as *battingLineUpTemp... Why is my code refusing to let me change the order of this NSMutableOrderedSet!? Is it CoreData being a massive pain in the arse once again?
Edit 1 I have also made sure that the object that I am replacing and the one which it is replacing are different by NSLogging within the for loop... the NSMutableOrderedSet is simply refusing to be rearranged!