swift中类型''没有成员'的值

时间:2017-08-14 10:19:16

标签: ios swift

以下代码在img.attr('src', slides[index].img); img.css('height','100%'); img.css('width','97%'); 行中提供错误value of type 'ViewController' has no member 'retrieveContactsWitStore',无论使用self.retrieveContactsWithStore(store: store)关键字。我提到了许多类似的问题,但我没有得到任何有效的解决方案和解释。任何人都可以解释为什么它会给出这个错误以及如何克服这个错误?

self

1 个答案:

答案 0 :(得分:0)

retrieveContactsWithStore

的函数@IBAction必须
@IBAction func btnContactsTapped() 
{
    let store = CNContactStore()

    if CNContactStore.authorizationStatus(for: .contacts) == .notDetermined {
        store.requestAccess(for: .contacts, completionHandler: { (authorized, error) in
            if authorized {
                self.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 {
            print("Contacts: \(contacts)")
        }
    } catch {
        print(error)
    }
}