代碼如下:
NSArray *array1 = @[@"2016-10-01",@"2016-10-02",@"2016-10-03",
@"2016-10-01",@"2016-10-02",@"2016-10-03",
@"2016-10-01",@"2016-10-02",@"2016-10-03",
@"2016-10-01",@"2016-10-02",@"2016-10-03",
@"2016-10-01",@"2016-10-02",@"2016-10-03",
@"2016-10-01",@"2016-10-02",@"2016-10-03",
@"2016-10-04",@"2016-10-06",@"2016-10-08",
@"2016-10-05",@"2016-10-07",@"2016-10-09"];
NSMutableArray *array = [NSMutableArray arrayWithArray:array1];
NSMutableArray *dateMutablearray = [@[] mutableCopy];
for (int i = 0; i < array.count; i ++) {
NSString *string = array[i];
NSMutableArray *tempArray = [@[] mutableCopy];
[tempArray addObject:string];
for (int j = i+1; j < array.count; j ++) {
NSString *jstring = array[j];
if([string isEqualToString:jstring]){
[tempArray addObject:jstring];
[array removeObjectAtIndex:j];
j -= 1;
}
}
[dateMutablearray addObject:tempArray];
}
NSLog(@"dateMutable:%@",dateMutablearray);
輸出結(jié)果是: