我有以下代码来打印联系人:
let people = ABAddressBookCopyArrayOfAllPeople(addressBook).takeRetainedValue() as NSArray as [ABRecord]
for person in people {
println(ABRecordCopyCompositeName(person).takeRetainedValue())
}
在迭代people
数组后,程序总是崩溃。该数组有6个AnyObject
类型的元素。这可能是演员问题吗?
我得到的错误是:Thread_1 EXC_BREAKPOINT (code = EXC_i386_BPT, subcode=0x0)
答案 0 :(得分:0)
可能在其他地方发生了错误。我尝试下面的代码,它工作正常。
var addressBook: ABAddressBookRef? = extractABAddressBookRef(ABAddressBookCreateWithOptions(nil, nil))
ABAddressBookRequestAccessWithCompletion(addressBook, { success, error in
if success {
let people = ABAddressBookCopyArrayOfAllPeople(addressBook).takeRetainedValue() as NSArray as [ABRecord]
for person in people {
println(ABRecordCopyCompositeName(person).takeRetainedValue())
}
}
})