1

I am testing with iOS AddressBook framework and I am trying to figure what, what's the best way to extract the value at specific label and wondering at the same time if the order of these labels change, for any random reason.

This is what I am doing when I am adding a new contact or adding to an existing one:

 let phone:ABMutableMultiValue = ABMultiValueCreateMutable(
        ABPropertyType(kABStringPropertyType)).takeRetainedValue()
 ABMultiValueAddValueAndLabel(phone, phoneNumber, kABPersonPhoneMainLabel, nil) 

And later on in the delegate call to unknownPersonViewController() I am doing this:

let phone: ABMultiValueRef = ABRecordCopyValue(person,
                kABPersonPhoneProperty).takeRetainedValue()
firstPhone = ABMultiValueCopyValueAtIndex(phone, 0).takeRetainedValue() as! String

Notice that I am assuming that the main label is at index 0. I know that a comparison with CFString label is possible, but these labels look funny, giving me this weird gut feeling when comparing agains them. So, I am not really sure how to go about this.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mickey Mouse
  • 1,731
  • 3
  • 24
  • 40

1 Answers1

1

You should not assume any order. You have to read the value of the label. They do "look funny" but they are easy to deal with: they are of the form "_$!<Label>!$_", where "_$!<" and ">!$_" are merely delimiters that you can rely on.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Also notice that there is no concept of "main label". The user can have these phone numbers in any order: you have no way of knowing which phone number is considered "main", if any. – matt Jun 04 '15 at 18:02
  • Ok, thanks @matt for pointing this out. I wanted to know this from someone's experience :) – Mickey Mouse Jun 04 '15 at 18:33
  • By the way, I didn't notice this till now, but I'm a big fan of your book! Thanks for putting such an amazing effort into it. – Mickey Mouse Jun 04 '15 at 20:43
  • Thanks, glad if I'm able to help! – matt Jun 04 '15 at 22:12