Most part of AddressBook framework is deprecated in iOS 9. In the new Contacts Framework documentation only shows how to fetch records matches a NSPredicate, bu
@rocolitis 's answer in swift! His answer is the most correct way of doing this according to Apple's documentation.
let contactStore = CNContactStore()
let keys = [CNContactPhoneNumbersKey, CNContactFamilyNameKey, CNContactGivenNameKey, CNContactNicknameKey] as [CNKeyDescriptor]
let request = CNContactFetchRequest(keysToFetch: keys)
try? contactStore.enumerateContacts(with: request) { (contact, error) in
// Do something with contact
}
You should probably check your access to your contacts first!
let authorization = CNContactStore.authorizationStatus(for: CNEntityType.contacts)
switch authorization {
case .authorized: break
case .denied: break
case .restricted: break
case .notDetermined: break
}