标签:
NSArray NSMutableArray的声明
注:NSArray与NSMutableArray中只能存放OC对象类型数据,不能存放int, float, double, struct, enum类型数据
NSArray *array1 = @[@"first", @"second", @"third"];
NSArray *array2 = [NSArray arrayWithObjects:@"one", @"two", @"three", nil]; // 不常用
NSMutableArray *array3 = @[@"ios", @"oc", @"swift"];
NSMutableArray *array4 = [NSMutableArray arrayWithObjects:@"c", @"html", @"css", nil]; //不常用
[array1 addObject:@"perl"];
[array1 removeObject:@"first"];
[array1 removeObjectAtIndex:2];
NSUInteger count = array4.count; // 返回OC中对象总个数
NSString *str1 = array4[1]; // 取出array4中下标为1的对象
NSString *str2 = [array4 objectAtIndex:1]; //取出array4中下标为1的对象(不常用)
// NSSArray的遍历
[array4 enumerateWithObjectsUsingBlock:
^(id obj, NSUInteger idx, BOOL *stop){
NSLog(@"%ld --- %@", idx, obj);
// 当下标为1时停止输出
if(idx == 1){
*stop = YES;
}
}
];
标签:
原文地址:http://www.cnblogs.com/lianfu/p/4649356.html