main.m
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
//创建数组对象
NSArray *array1 = @[ @(1),@(2),@(3),@(4)];
NSArray *array2 = @[@"apple" ,@"pear",@"grape",@"banana",@"orange"];
NSLog(@"%ld",array1.count);//打印数组array1的长度
//数组的循环遍历
for(int i=0;i<array1.count;i++){
NSLog(@"%@",array1[i]);
}
//调用数组的排序方法实现排序
array2 = [array2 sortedArrayUsingSelector:@selector(compare:)];
//for-in循环遍历数组(只读循环)
for (NSString *str in array2) {
NSLog(@"%@",str);
}
//创建一个可变的空数组!
NSMutableArray *array3 = [NSMutableArray array];
NSLog(@"%@",array3);
//arrayWithObjects可以将后面的字符装进array4
NSMutableArray *array4 = [NSMutableArray arrayWithObjects:@"hello",@"are",@"you",
@"luhan", nil];
NSLog(@"%@",array4);
[array4 removeObject:@"hello"];//把array4的hello元素移除
[array4 addObject:@"honey"];//给array4添加元素honey
[array4 insertObject:@"darling" atIndex:0];//在array4的第0个元素加入darling
NSLog(@"%@",array4);
//把array装进array5
NSMutableArray *array5 = [NSMutableArray arrayWithArray:array1];
[array5 addObject:@(5)];//把array5加入元素5
NSLog(@"%@",array5);
}
return 0;
}