[英]Delete number phone Contact - Swift 3 - 4
I want to delete a contact number, I use ContactsUI 我想删除一个联系电话,我使用ContactsUI
//only do this to the first contact matching our criteria
guard let contact = contacts?.first else{
return
}
let editContact = contact.mutableCopy() as! CNMutableContact
editContact.phoneNumbers[1]..... ?
in editContact.phoneNumbers[1].. I want to eliminate that number that is in that position 在editContact.phoneNumbers [1]中。我想消除该位置的那个号码
to edit it, I edit it in this way. 编辑它,我以这种方式编辑它。 and it works well 而且效果很好
editContact.phoneNumbers[1] = CNLabeledValue(label: "home",
value: CNPhoneNumber(stringValue: "1234567"))
but how do I eliminate it 但是我怎么消除它
phoneNumbers
is an array. phoneNumbers
是一个数组。 Remove the desired element like you would any other array value: 像删除任何其他数组值一样删除所需的元素:
let editContact = contact.mutableCopy() as! CNMutableContact
editContact.phoneNumbers.remove(at: 1)
Of course I'd make sure there are at least 2 phone numbers before doing that. 当然,在执行此操作之前,我将确保至少有两个电话号码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.