- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据我的要求,我需要对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);
最佳答案
您不能在单个操作中完成此操作,但是可以将排序描述符应用于唯一操作的结果:
NSArray *uniqueArray = [mYearsArray valueForKeyPath:@"@distinctUnionOfObjects.self"];
NSArray *sortedUniqueArray = [uniqueArray sortedArrayUsingDescriptors:sortDescriptors];
mYearsArray = [sortedUniqueArray mutableCopy];
关于iphone - 我们可以一次使用排序描述符和@distinctUnionOfObjects吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18056602/
我创建了简单的 XCTest 来测试 distinctUnionOfObjects。除了 isKindOfClass (Last XCTAssertTrue) 之外,所有测试用例都通过了。知道为什么在
我有一个带有 NSDictionary 的 NSArray 并尝试使用以下代码删除重复项: NSDictionary *arnold = @{@"name" : @"arnold", @"state"
我正在尝试从 this 开始快速制作日历很好的例子。到目前为止,我设法显示了网格和所有自定义 UICollectionViewLayout 的补充 View 。问题是当我试图在日历中添加事件时。日行和
我想获取 Realm 中某列的所有不同记录 我知道 Realm 中有一个方法 distinctUnionOfObjects 可以解决这个问题。 谁能帮帮我? 提前致谢。 最佳答案 虽然 Realm 确
我有一个使用 Core Data 的应用程序,它具有我想作为分组依据的关系。我的 .xcdatamodel 文件生成了 NSManagedObject 类,大部分情况下一切正常。 鉴于 parent
我是一名优秀的程序员,十分优秀!