#importint main(int argc, const char * argv[]){ //数组中建议存储同类型的数据元素 NSArray * array = @[@"one",@"two",@"three"]; for (int i = 0; i < array.count; i++) { NSString * str = array[i]; NSLog(@"array[%d] = %@",i,str); } //使用增强for循环遍历数组 for (NSString * str in array) { NSLog(@"%@",str); } return 0;}
#importint main(int argc, const char * argv[]){ NSArray * array = @[@"1",@"2",@"3",@"4"]; NSLog(@"before sort%@",array); //排序 NSComparisonResult cmp = [@"a" compare:@"b"]; // NSLog(@"%d",cmp); array = [array sortedArrayUsingSelector:@selector(compare:)]; //正序 左边小于右边 NSLog(@"after sort %@",array); //(void)(^block)(int a ,int b); NSArray * arry1 = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2) { return [obj1 compare:obj2]; }];}