Created
January 17, 2010 19:09
-
-
Save cacaodev/279516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation CPArray (MoveIndexes) | |
- (void)moveIndexes:(CPIndexSet)indexes toIndex:(int)insertIndex | |
{ | |
var aboveCount = 0, | |
object, | |
removeIndex; | |
var index = [indexes lastIndex]; | |
while (index != CPNotFound) | |
{ | |
if (index >= insertIndex) | |
{ | |
removeIndex = index + aboveCount; | |
aboveCount ++; | |
} | |
else | |
{ | |
removeIndex = index; | |
insertIndex --; | |
} | |
object = [self objectAtIndex:removeIndex]; | |
[self removeObjectAtIndex:removeIndex]; | |
[self insertObject:object atIndex:insertIndex]; | |
index = [indexes indexLessThanIndex:index]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment