如何对 NSSet 进行分组和计数?
如何对核心数据实体中的记录进行分组,然后对它们进行计数,以便找到计数最高的组?
我有一个“集合”,它有许多“腿”,每条腿都有一个“获胜者”。我想回答的问题是:谁赢得了最多的腿。
感谢帮助。哦,新年快乐!
How do I tackle grouping the records in a Core Data entity and then counting them so I can find the group with the highest count?
I have a 'set' which has many 'legs' each of which has one 'winner'. The question I am trying to answer is: Who has won the most legs.
Help is appreciated. Oh, and happy new year!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
迭代该组并计算每个“获胜者”的“腿”。将腿计数保存在字典中:
现在您需要在新字典中找到具有最高值的键。
Iterate through the set and count the 'legs' for each 'winner'. Save the leg-counts in a dictionary:
Now you need to find the key in the new dictionary with the highest value.