#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSMutableArray *listOfNames = [[NSMutableArray alloc] init];
[listOfNames addObject:@"Jack"];
[listOfNames addObject:@"Cindy"];
[listOfNames addObject:@"Lucy"];
NSLog(@"OBJECTS ADDED TO ARRAY: %@", listOfNames);
// 在1号索引处插入 @“Cook” 原先在此处的元素后移,索引数变为2
[listOfNames insertObject:@"Cook" atIndex:1];
NSLog(@"AFTER INSERTING, THE ARRAY: %@", listOfNames);
// 把3号索引处的对象替换成 @“Jim”
[listOfNames replaceObjectAtIndex:3 withObject:@"Jim"];
NSLog(@"AFTER'Lucy' REPLACED BY 'Jim', THE ARRAY IS %@", listOfNames);
// 把0号和1号处的索引对象进行换位
[listOfNames exchangeObjectAtIndex:0 withObjectAtIndex:1];
NSLog(@"OBJECT AT INDEX 0 EXCHANGED WITH OBJECT AT INDEX 1 IN ARRAY: %@",listOfNames);
// 移除指定的对象
[listOfNames removeObject:@"Jack"];
NSLog(@"THE ARRAY: %@", listOfNames);
// 移除数组最后一个对象
[listOfNames removeLastObject];
NSLog(@"THE ARRAY: %@", listOfNames);
// 移除数组中的使用对象
[listOfNames removeAllObjects];
NSLog(@"THE ARRAY: %@", listOfNames);
}
return 0;
}
操纵数组内容
最新推荐文章于 2021-11-19 17:12:36 发布