我正在尝试从通讯录中获取联系人。我的代码在 Objective C 中正常工作,但是当我将其转换为 swift 时出现错误
无法将“Swift.UnsafePointer<()>”类型的值转换为“Swift.AnyObject”
下面是我的代码
var errorRef: Unmanaged<CFError>? = nil
let addressBook: ABAddressBookRef = ABAddressBookCreateWithOptions(nil, &errorRef).takeRetainedValue()
let allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook).takeRetainedValue() as NSArray //as [ABRecordRef]
let numberOfPeople = ABAddressBookGetPersonCount(addressBook)
for (var i=0; i < numberOfPeople; i++){
runOnMainQueueWithoutDeadlocking({ () -> () in
ProgressHUD.show("Reading Contact \(i) out of \(numberOfPeople)")
})
let aPerson = CFArrayGetValueAtIndex(allPeople, i) as! ABRecordRef //Error here
}
如何将记录转换为 ABRecordRef。请帮忙