以下代碼在self.retrieveContactsWithStore(store: store)
行中給出錯誤value of type 'ViewController' has no member 'retrieveContactsWitStore'
,與使用self
關鍵字無關。我提到了很多類似的問題,但我沒有得到任何解決方案和解釋。任何人都可以解釋爲什麼它給這個錯誤,以及如何克服這個錯誤?類型''中沒有成員''的值快速
@IBAction func btnContactsTapped() {
let store = CNContactStore()
if CNContactStore.authorizationStatus(for: .contacts) == .notDetermined {
store.requestAccess(for: .contacts, completionHandler: { (authorized: Bool, error: Error?) -> Void in
if authorized {
retrieveContactsWithStore(store: store)
}
})
} else if CNContactStore.authorizationStatus(for: .contacts) == .authorized {
self.retrieveContactsWithStore(store: store)
}
func retrieveContactsWithStore(store: CNContactStore) {
do {
let groups = try store.groups(matching: nil)
let predicate = CNContact.predicateForContactsInGroup(withIdentifier: groups[0].identifier)
//let predicate = CNContact.predicateForContactsMatchingName("John")
let keysToFetch = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactEmailAddressesKey] as [Any]
let contacts = try store.unifiedContacts(matching: predicate, keysToFetch: keysToFetch as! [CNKeyDescriptor])
// self.objects = contacts
DispatchQueue.main.async(execute: {() -> Void in
print("Contacts: \(contacts)")
})
} catch {
print(error)
}
}
}
你的函數'retrieveContactsWithStore'是* *裏面的'btnContactsTapped'功能。將它移出 – Paulw11
您的縮進看起來很糟糕。可能是事業的一部分。 –