// // NSArray+MBAdditions.m // MBMenuExtra // // Created by Michael Bishop on 1/23/10. // Copyright 2010 Perforce Software. All rights reserved. // #import "NSArray+NGAAdditions.h" #import "NGAUtilities.h" @implementation NSArray (NGAAdditions) -(id)arrayByRemovingObjects:(NSArray*)excludedObjects { if ( excludedObjects == nil || [excludedObjects count] == 0 ) return AUTORELEASE( RETAIN(self) ); NSMutableArray * survivingObjects = [NSMutableArray arrayWithCapacity:[self count]]; for (id item in self) { if ( ![excludedObjects containsObject:item] ) [survivingObjects addObject:item]; } return [NSArray arrayWithArray:survivingObjects]; } -(id)arrayByRemovingObject:(id)excludedObject { if ( excludedObject == nil ) return AUTORELEASE( RETAIN(self) ); return [self arrayByRemovingObjects:[NSArray arrayWithObject:excludedObject]]; } -(NSDictionary*)NGA_dictionaryByKeyingOnKey:(NSString*)key { NSMutableDictionary * organizedResults = [NSMutableDictionary dictionaryWithCapacity:[self count]]; for (NSDictionary * dictionary in self) { NSString * keyedValue = [dictionary valueForKey:key]; if ( keyedValue ) [organizedResults setObject:dictionary forKey:keyedValue]; } return organizedResults; } -(NSDictionary*)NGA_dictionaryByKeyingOnIndex:(NSInteger)index { if ( index < 0 ) return nil; NSMutableDictionary * organizedResults = [NSMutableDictionary dictionaryWithCapacity:[self count]]; for (NSArray * array in self) { if ( index < [array count] ) { NSString * keyedValue = [array objectAtIndex:index]; [organizedResults setObject:array forKey:keyedValue]; } } return organizedResults; } @end @implementation NSArray (NGAPair) +(NSArray*) arrayFromFirstObject:(id)firstObject secondObject:(id)secondObject { return [NSArray arrayWithObjects:firstObject, secondObject, nil]; } -(id) firstObject { if ( [self count] < 1 ) return nil; return [self objectAtIndex:0]; } -(id) secondObject { if ( [self count] < 2 ) return nil; return [self objectAtIndex:1]; } @end @implementation NSMutableArray (NGAArrayAdditions) -(void)NGA_setObject:(id)object atIndex:(NSUInteger)index { if (index < [self count]) { [self replaceObjectAtIndex:index withObject:object]; return; } // INVARIANT: index >= [self count] const NSUInteger overflow = index - [self count]; for ( int i = 0; i < overflow; i++ ) [self addObject:[NSNull null]]; [self addObject:object]; } @end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 20722 | jdputsch | initial branch, prep for -Zapp= support | ||
//guest/michael_bishop/MacMenu/src/NGAUtilities/Source/NSArray+NGAAdditions.m | |||||
#1 | 8331 | Matt Attaway |
Adding initial version of MacMenu for Perforce MacMenu is a helpful Perforce client that sits in your toolbar. It allows you to run standard Perforce operations on the document that is open the currently active editor/viewer. |