我正在对 nsmutableSet 进行排序,但遇到了一个奇怪的问题。
NSArray *data = @[@[@"1",@"2",@"3"],
@[@"2",@"3",@"4",@"5",@"6"],
@[@"8",@"9",@"10"],
@[@"15",@"16",@"17",@"18"]];
NSArray *sortArr = [[NSArray alloc] init];
NSMutableArray *Data = [[NSMutableArray alloc] init];
NSMutableSet *interSection = [[NSMutableSet alloc] init];
interSection = [NSMutableSet setWithArray:[data objectAtIndex:0]];
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"description" ascending:YES ];
for (int i =1; i < 4; i ++) {
if ([interSection intersectsSet:[NSSet setWithArray:[data objectAtIndex:i]]]) {
[interSection unionSet:[NSSet setWithArray:[data objectAtIndex:i]]];
}
else{
sortArr = [interSection sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
[Data addObject:sortArr];
interSection = [NSMutableSet setWithArray:[data objectAtIndex:i]];
}
}
if ([interSection count] != 0) {
sortArr = [interSection sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]];
[Data addObject:sortArr];
}
NSLog(@"%@",Data);
但输出是:(1、2、3、4、5、6)、(10、8、9)、(15、16、17、18))
为什么是 (10,8,9) 但 (8,9,10) ?
有人知道答案吗?