Since NSArray objects are immutable (cannot modify the objects that they contain), there is no need to configure the capacity of NSArrays.
However, you could write a category that did something according to what you want:
@interface NSArray (Resizing) -(NSArray *) resize:(NSInteger) newSize; @end @implementation NSArray (Resizing) -(NSArray *) resize:(NSInteger) newSize { int size = (newSize > [self count]) ? self.count : newSize; NSMutableArray *array = [NSMutableArray arrayWithCapacity:size]; for(int i = 0; i < size; i++) [array addObject:[self objectAtIndex:i]]; return [NSArray arrayWithArray:array]; } @end
source share