NSArray *array1 = [NSArray arrayWithObjects:@"a", @"b", @"c", nil nil];
NSArray *array2 = [NSArray arrayWithObjects:@"b", @"a", @"c", nil nil];
bool bol = false;
//创建俩新的数组
NSMutableArray *oldArr = [NSMutableArray arrayWithArray:array1];
NSMutableArray *newArr = [NSMutableArray arrayWithArray:array2];
//对数组1排序。
[oldArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
return obj1 > obj2;
}];
////上个排序好像不起作用,应采用下面这个
[oldArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2){return [obj1 localizedStandardCompare: obj2];}];
//对数组2排序。
[newArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
return obj1 > obj2;
}];
////上个排序好像不起作用,应采用下面这个
[newArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2){return [obj1 localizedStandardCompare: obj2];}];
if (newArr.count == oldArr.count) {
bol = true;
for (int16_t i = 0; i < oldArr.count; i++) {
id c1 = [oldArr objectAtIndex:i];
id newc = [newArr objectAtIndex:i];
if (![newc isEqualToString:c1];) {
bol = false;
break;
}
}
}
if (bol) {
NSLog(@"两个数组的内容相同!");
}
else {
NSLog(@"两个数组的内容不相同!");
}