NSArray *arr1 = @[@"1",@"3",@"7",@"6",@"4",];
NSArray *arr2 = @[@"2",@"4",@"7",@"6",@"9"];
//数组合并
NSArray*arr = [arr1arrayByAddingObjectsFromArray:arr2];
//使用NSSet集合去重,NSSet是集合的意思
NSSet*set = NSSetsetWithArray:arr];
//数组排序
NSArray*array = [setsortedArrayUsingDescriptors:@[[NSSortDescriptorsortDescriptorWithKey:nilascending:YES]]];
第二种方式
NSMutableArray*array2 = [NSMutableArray array];
for (int i =0; i<arr1.count; i++){
for (int j = 0;j<arr2.count.count; j++){
if(arr1[i]==arr2[j]){
[array2 addObject:arr1[i]];
}}}
NSArray*paixu = [array2sortedArrayUsingDescriptors:@[[NSSortDescriptorsortDescriptorWithKey:nilascending:YES]]];
NSLog(@"array2 =%@",paixu);
网友评论