简体   繁体   English

如何在Xcode 7 / iOS 9中找到CNGroup的成员数

[英]How do i find the number of members of a CNGroup in Xcode 7/ iOS 9

I want to display the names of each of the CNGroups in an iPhone's contacts database, and the number of people in each group. 我想在iPhone的联系人数据库中显示每个CNGroups的名称,以及每个组中的人数。

I have the array of CNGroups , so I can get the name and the identifier properties of each group 我有CNGroups数组,所以我可以获取每个组的名称和标识符属性

I could call 我可以打电话

[CNContact predicateForContactsInGroupWithIdentifier: theGroup.identifier] ,

then create a fetch on the CNContactStore using that predicate and then count the number of elements of the array that is returned and that works. 然后使用该谓词在CNContactStore上创建访CNContactStore ,然后计算返回并起作用的数组元素的数量。

That seems a long winded and processor intensive way of finding out the number of members, so much so that I'm sure there must be a easier way to achieve this. 找出成员数量的方法似乎耗时长且需要大量处理器,因此我确信必须有一种更简单的方法来实现这一点。

Have I missed something or is this the way it has to be done? 我错过了什么吗,还是必须这样做?

Thanks. 谢谢。

That would be how I would do it, if you're finding it to be hitting performance you could always dispatch it onto a background queue since according to the documentation 那就是我要这样做的方式,如果您发现它的性能下降,则可以始终将其分派到后台队列中,因为根据文档

this framework is optimized for thread-safe, read-only usage 该框架针对线程安全的只读使用进行了优化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM