NSPredicate 对数组进行排序并按 DESC 顺序
我有一个包含 TBPosts
的 NSMutableArray
,我想根据其 commentsCount
和 likesCount
按降序过滤TBPost
。
最初,过滤数组中的第一个对象将是评论和点赞数量最多的对象,可以通过将两者相加得出。因此,我尝试了以下查询并收到无法解析错误。请问你能告诉我哪里出错了吗?
[posts filterUsingPredicate:[NSPredicate predicateWithFormat:@"post.commentsCount + post.likesCount DESC"]];
I have an NSMutableArray
containing TBPosts
that I would like to filter in descending order according to the commentsCount
and likesCount
of the TBPost
.
Initially, the first object in the filtered array will be the object with the largest number of comments and likes, which can be worked out by adding the two together. So I tried the following query and receive an Unable to Parse error. Please can you tell me where I am going wrong?
[posts filterUsingPredicate:[NSPredicate predicateWithFormat:@"post.commentsCount + post.likesCount DESC"]];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
过滤不是排序。您使用了错误的方法。
使用比较器,它看起来像这样:
filtering is not sorting. You are using the wrong method.
Using a comparator, it would look like this: