【发布时间】:2017-06-15 03:06:14
【问题描述】:
我正在寻找一种方法来获取与联系人容器 (CNContainer) 相关的组 (CNGroup) 列表。当我使用 predicate 时,它失败了。
我使用的代码是
func populateGroups(tableView:NSTableView,container:CNContainer){
print("populateGroups.start")
print(container.name)
print(container.identifier)
let contactStore = CNContactStore()
do {
let groupsPredicate = CNGroup.predicateForGroups(withIdentifiers: [container.identifier])
groups = try contactStore.groups(matching: groupsPredicate)
groupNames.removeAll();
for group:CNGroup in groups {
self.groupNames.append(group.name)
}
tableView.reloadData()
} catch {
print( "Unexpected error fetching groups")
}
print("populateGroups.finish")
}
我收到了一个对我来说没有意义的错误。
行 groups = try contactStore.groups(matching: groupsPredicate) 导致错误。
[Accounts] 无法更新标识符为 47008233-A663-4A52-8487-9D7505847E29 的帐户,错误:Error Domain=ABAddressBookErrorDomain Code=1002 "(null)"
这很令人困惑,因为我没有更新任何帐户。
如果我将该行代码更改为组 = 尝试 contactStore.groups(matching: nil) 我得到所有容器的所有组。
如何创建一个谓词来返回属于 CNContactContainer 的所有 CNGroup?
【问题讨论】:
标签: swift macos cncontactstore