Changeset 5167

Show
Ignore:
Timestamp:
01/16/08 08:30:18 (6 months ago)
Author:
morris
Message:

Make -moveObjectAtIndex:toIndex: return index of insert

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredAdditions/trunk/NSArray-WIAdditions.h

    r4972 r5167  
    5252@interface NSMutableArray(WIMutableArrayAdditions) 
    5353 
    54 - (void)moveObjectAtIndex:(NSUInteger)from toIndex:(NSUInteger)to; 
     54- (NSUInteger)moveObjectAtIndex:(NSUInteger)from toIndex:(NSUInteger)to; 
    5555- (void)reverse; 
    5656- (void)shuffle; 
  • WiredAdditions/trunk/NSArray-WIAdditions.m

    r4972 r5167  
    250250@implementation NSMutableArray(WIMutableArrayAdditions) 
    251251 
    252 - (void)moveObjectAtIndex:(NSUInteger)from toIndex:(NSUInteger)to { 
    253         id              object; 
    254  
    255         if(from != to) { 
    256                 object = [self objectAtIndex:from]; 
    257  
    258                 [object retain]; 
    259                 [self removeObjectAtIndex:from]; 
    260                 [self insertObject:object atIndex:to <= from ? to : to - 1]; 
    261                 [object release]; 
    262         } 
     252- (NSUInteger)moveObjectAtIndex:(NSUInteger)from toIndex:(NSUInteger)to { 
     253        id                      object; 
     254        NSUInteger      index; 
     255 
     256        if(from == to) 
     257                return from; 
     258         
     259        object = [self objectAtIndex:from]; 
     260        index = (to <= from) ? to : to - 1; 
     261 
     262        [object retain]; 
     263        [self removeObjectAtIndex:from]; 
     264        [self insertObject:object atIndex:index]; 
     265        [object release]; 
     266         
     267        return index; 
    263268} 
    264269