NSMutableArray 添加移动位置函数

MoveArray.h@interface NSMutableArray (HF)
- (void)moveObjectFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;


#import "MoveArray.h"


@implementation NSMutableArray (HF)
- (void)moveObjectFromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex
{

if (toIndex != fromIndex && fromIndex < [self count] && toIndex< [self count]) {

id obj = [self objectAtIndex:fromIndex];
[obj retain];
[self removeObjectAtIndex:fromIndex];
if (toIndex >= [self count]) {
[self addObject:obj];
} else {
[self insertObject:obj atIndex:toIndex];
}
[obj release];
}
}




@end:

你可能感兴趣的:(NSMutableArray 添加移动位置函数)