Can I shift the objects in a NSMutableArray without creating a temporary array?
问题 I thought I had it with, void shiftArray(NSMutableArray *mutableArray, NSUInteger shift) { for (NSUInteger i = 0; i < [mutableArray count]; i++) { NSUInteger newIndex = (i + shift) % [mutableArray count]; [mutableArray exchangeObjectAtIndex:i withObjectAtIndex:newIndex]; } } which turns 0,1,2,3,4 into 0,2,3,4,1 when I shift by one. The expected result is 4,0,1,2,3 I feel like I'm missing something obvious... Update: Thanks Matthieu, this is what my function looks like now. void