Disabling code signing only in Debug is not possible with Sparkle.
[enjoyable.git] / Categories / NSMutableArray+MoveObject.m
index 8d9a4ee6978e927c5ca9e42375720f7871de4d30..6c7987e252b8c20f176a655f4e8e99e5d705ed96 100644 (file)
     [self insertObject:obj atIndex:dst > src ? dst - 1 : dst];
 }
 
+- (BOOL)moveFirstwards:(id)object upTo:(NSUInteger)minIndex {
+    NSUInteger idx = [self indexOfObject:object];
+    if (idx > minIndex && idx != NSNotFound) {
+        [self exchangeObjectAtIndex:idx withObjectAtIndex:idx - 1];
+        return YES;
+    } else {
+        return NO;
+    }
+}
+
+- (BOOL)moveLastwards:(id)object upTo:(NSUInteger)maxIndex {
+    maxIndex = MIN(self.count - 1, maxIndex);
+    NSUInteger idx = [self indexOfObject:object];
+    if (idx < maxIndex && idx != NSNotFound) {
+        [self exchangeObjectAtIndex:idx withObjectAtIndex:idx + 1];
+        return YES;
+    } else {
+        return NO;
+    }
+}
+
+- (BOOL)moveFirstwards:(id)object {
+    return [self moveFirstwards:object upTo:0];
+}
+
+- (BOOL)moveLastwards:(id)object {
+    return [self moveLastwards:object upTo:NSNotFound];
+}
+
+
 @end