我試圖讓使用下面的代碼觸點崩潰:應用程序同時從iPhone獲取聯繫人號碼在SWIFT
var addressBook: ABAddressBook!
let addressBookRef: ABAddressBook = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue()
var arrContacts = [""]
var personNameContactNo:[String: String] = ["":""]
var arrOfDictContacts = NSMutableArray()
var Name: String!
if let people = ABAddressBookCopyArrayOfAllPeople(addressBook)?.takeRetainedValue() as? NSArray {
for person in people{
if let name = ABRecordCopyValue(person, kABPersonFirstNameProperty).takeRetainedValue() as? String {
Name = name
}
let numbers:ABMultiValue = ABRecordCopyValue(
person, kABPersonPhoneProperty).takeRetainedValue()
var number = ABMultiValueCopyValueAtIndex(numbers,0).takeRetainedValue() as! String
println("number = \(number)")
if(number.isEmpty) {
println("empty")
} else {
personNameContactNo.removeAll(keepCapacity: true)
personNameContactNo.updateValue(number, forKey:Name)
arrOfDictContacts.addObject(personNameContactNo)
}
println(personNameContactNo)
}
println(arrOfDictContacts)
}
what am expecting is: ["Arun":"123455"], ["John":"23456122"], etc...
它運行在模擬器不錯,但不是在設備上。也許這是由於一些零價值。 應用崩潰與以下信息:fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
你能指定你的代碼在哪一行崩潰嗎? – Shoaib
我不知道在哪一行,它沒有在崩潰時指向 – AAA
嘗試在我的答案中發佈的代碼。 – Shoaib