Skip to content

Instantly share code, notes, and snippets.

@cacaodev
Created January 17, 2010 19:09
Show Gist options
  • Save cacaodev/279516 to your computer and use it in GitHub Desktop.
Save cacaodev/279516 to your computer and use it in GitHub Desktop.
@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