Rupesh
Rupesh

Reputation: 7906

iPhone: Create Custom Field in contacts

i am developing a application in which i add contact to contact List. i am able to basic info like name, address, email, phone, notes etc. but i want to add some custom field like userLabel1, userValue1 , bioPersonal, bioWork, bioOther. so i want to add custom fields to address Book'contacts.

whether it is possible to add custom field to contact? if yes , then please suggest any link or sample code?

Upvotes: 2

Views: 6568

Answers (2)

K Ravi Kumar
K Ravi Kumar

Reputation: 71

    let store = CNContactStore()

    // phoneNumberToEdit is the CNContact which you need to update
    guard var mutableCont = phoneNumberToEdit?.mutableCopy() as? CNMutableContact else  { return }
    let phoneNumber = CNPhoneNumber(stringValue: "0123456789")
    var currentContact = CNLabeledValue(label: "MyCustomLabel", value: phoneNumber)
    mutableCont.phoneNumbers = [currentContact]

    let request2 = CNSaveRequest()
    request2.update(mutableCont)
    do{
    try store.execute(request2)
    } catch let error{
    print(error)
    }

Upvotes: 0

F'x
F'x

Reputation: 12298

Basically, there is no way to do that. Address Book doesn't let you add custom fields. However, what you can do is put your data in the "Notes" field for each contact. That will, however, look weird in apps other than yours.

Upvotes: 4

Related Questions