Catégorie conforme à l'ARC:
NSMutableArray + Convenience.h
@interface NSMutableArray (Convenience)
- (void)moveObjectAtIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;
@end
NSMutableArray + Convenience.m
@implementation NSMutableArray (Convenience)
- (void)moveObjectAtIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex
{
// Optional toIndex adjustment if you think toIndex refers to the position in the array before the move (as per Richard's comment)
if (fromIndex < toIndex) {
toIndex--; // Optional
}
id object = [self objectAtIndex:fromIndex];
[self removeObjectAtIndex:fromIndex];
[self insertObject:object atIndex:toIndex];
}
@end
Usage:
[mutableArray moveObjectAtIndex:2 toIndex:5];