2 // NSMutableArray+MoveObject.m
5 // Created by Joe Wreschnig on 3/7/13.
9 #import "NSMutableArray+MoveObject.h"
11 @implementation NSMutableArray (MoveObject)
13 - (void)moveObjectAtIndex:(NSUInteger)src toIndex:(NSUInteger)dst {
15 [self removeObjectAtIndex:src];
16 [self insertObject:obj atIndex:dst];
19 - (BOOL)moveFirstwards:(id)object upTo:(NSUInteger)minIndex {
20 NSUInteger idx = [self indexOfObject:object];
21 if (idx > minIndex && idx != NSNotFound) {
22 [self exchangeObjectAtIndex:idx withObjectAtIndex:idx - 1];
29 - (BOOL)moveLastwards:(id)object upTo:(NSUInteger)maxIndex {
30 maxIndex = MIN(self.count - 1, maxIndex);
31 NSUInteger idx = [self indexOfObject:object];
32 if (idx < maxIndex && idx != NSNotFound) {
33 [self exchangeObjectAtIndex:idx withObjectAtIndex:idx + 1];
40 - (BOOL)moveFirstwards:(id)object {
41 return [self moveFirstwards:object upTo:0];
44 - (BOOL)moveLastwards:(id)object {
45 return [self moveLastwards:object upTo:NSNotFound];