1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... //array创建 NSArray *array=[NSArray array]; //空数组 NSArray *array2= [NSArray arrayWithObject:@"jack"]; NSArray *array3= [NSArray arrayWithObjects:@"jack",@"rose",nil]; NSArray *array4=@[@"jack",@"rose",@"jone"]; //数组元素 [array2 count]; array2.count; //元素访问 [array3 objectAtIndex:1]; array3[1]; NSLog(@"数组array2的大小%d",array2.count); NSLog(@"数组array2第1个元素是:%d",[array3 objectAtIndex:1]); //遍历 for (int i=0; i<array4.count; i++) { NSLog(@"%d---%@",i,array4[i]); } for (id obj in array4) { NSLog(@"%d---%@",[array4 indexOfObject:obj],obj); } [array4 enumerateObjectsUsingBlock: ^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { NSLog(@"%d---%@",idx,obj); if (idx==1) { *stop=YES; } }]; } return 0; }
|