当没有 phone 没有分配给联系人时,获取联系人不会崩溃

Fetching contact no crashes when there is no phone no assigned to the contact

我正在尝试读取联系人 phone 否。如果号码可用,下面的代码可以正常工作,但如果没有 phone no assigned to the contact ,它就会崩溃。阿努能告诉我怎么处理吗

((currentContact.phoneNumbers.first?.value)! as CNPhoneNumber).stringValue

您应该在 Swift...

中了解可选值
if let contactPhoneNumber = currentContact.phoneNumbers.first?.value?.stringValue {
    // do something with the value
} 
else {
    // the value isn't there 
}