标签:排序 遍历 数组 foundation框架 objective-c
#import <Foundation/Foundation.h> int 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; }
#import <Foundation/Foundation.h> int 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]; }]; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:排序 遍历 数组 foundation框架 objective-c
原文地址:http://blog.csdn.net/u012701023/article/details/47079495