给数组分配容量
//NSArray *array; array = [NSMutableArray arrayWithCapacity:20];
在数组末尾添加对象
//- (void) addObject: (id) anObject; //NSMutableArray *array = [NSMutableArray arrayWithObjects: @"One",@"Two",@"Three",nil]; [array addObject"Four"]; NSLog(@"array:%@",array);
删除数组中指定索引处对象
//-(void) removeObjectAtIndex: (unsigned) index; //NSMutableArray *array = [NSMutableArray arrayWithObjects: @"One",@"Two",@"Three",nil]; [array removeObjectAtIndex:1]; NSLog(@"array:%@",array);
数组枚举
1 //- (NSEnumerator *)objectEnumerator;从前向后 2 //NSMutableArray *array = [NSMutableArray arrayWithObjects: 3 @"One",@"Two",@"Three",nil]; 4 NSEnumerator *enumerator; 5 enumerator = [array objectEnumerator]; 6 7 id thingie; 8 while (thingie = [enumerator nextObject]) { 9 NSLog(@"thingie:%@",thingie); 10 } 11 12 //- (NSEnumerator *)reverseObjectEnumerator;从后向前 13 //NSMutableArray *array = [NSMutableArray arrayWithObjects: 14 @"One",@"Two",@"Three",nil]; 15 NSEnumerator *enumerator; 16 enumerator = [array reverseObjectEnumerator]; 17 18 id object; 19 while (object = [enumerator nextObject]) { 20 NSLog(@"object:%@",object); 21 } 22 23 //快速枚举 24 //NSMutableArray *array = [NSMutableArray arrayWithObjects: 25 @"One",@"Two",@"Three",nil]; 26 for(NSString *string in array) 27 { 28 NSLog(@"string:%@",string); 29 }