【发布时间】:2017-10-17 20:14:19
【问题描述】:
我在 Apple 开发人员文档中找到了以下代码,但我无法理解如何正确调用此函数。非常感谢任何指导。
func fetchContactsInGroup(with identifier: String, completion: @escaping (_ contacts: [CNContact]) -> Void) {
var result = [CNContact]()
// Fetch only the full name of a person or organization.
let request = CNContactFetchRequest(keysToFetch: [CNContactFormatter.descriptorForRequiredKeys(for: .fullName)])
// Predicate to fetch all contacts that are members of the specified group.
request.predicate = CNContact.predicateForContactsInGroup(withIdentifier: identifier)
contactStoreQueue.async {
do {
try self.store.enumerateContacts(with: request, usingBlock: {(contact, status) -> Void in
// Add each retured contact to result.
result.append(contact)
})
} catch let error as NSError {
print("Error \(error.localizedDescription)")
}
DispatchQueue.main.async {
completion(result)
}
}
}
【问题讨论】:
-
你没有得到哪一部分?
-
调用 func fetchContactsInGroup 的语法 - 完成:位是我的问题