小编Use*_*iOS的帖子

我们可以一次使用排序描述符和@distinctUnionOfObjects吗?

由于我的要求,我需要对我进行排序NSMutableArray并需要在该数组中放置唯一值.

这是我的代码,但我遇到的问题是我得到两个数组:一个具有不同的值,另一个没有明确的值但是已经排序.

/ *Making the years unique so that it will display only once*/
        mSortingArray = [mYearsArray valueForKeyPath:@"@distinctUnionOfObjects.self"] ;
        NSLog(@"mSortingArray%@",mSortingArray);

        /*Sorting the array to get the years in assending format*/
        NSSortDescriptor *sortDescriptor;
        sortDescriptor = [[NSSortDescriptor alloc]initWithKey:@"self"ascending:YES];
        NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
        [mYearsArray sortUsingDescriptors:sortDescriptors];
        NSLog(@"%@ :%@",mYearsArray,sortDescriptors);
Run Code Online (Sandbox Code Playgroud)

如何在一个数组中获得两个结果?

iphone nsmutablearray nssortdescriptor ios

1
推荐指数
1
解决办法
1483
查看次数

标签 统计

ios ×1

iphone ×1

nsmutablearray ×1

nssortdescriptor ×1