0

I'm trying to use AddressBook and AddressBookUI to show a view of the address book, where a user can then tap on a contact and then the phone number, and the app receives the phone number. I'm having an issue when I iterate through the ABMultiValue looking to find the entry with the selected identifier - the error "Binary operator '<' cannot be applied to two CFIndex operands" is raised on the line with the for loop (line 13).

I've pasted the code below - does anyone have any idea why this happening / what I can do to fix it? Thanks!

func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, didSelectPerson person: ABRecord!, property: ABPropertyID, identifier: ABMultiValueIdentifier) {
    self.peoplePickerNavigationController(peoplePicker, shouldContinueAfterSelectingPerson: person, property: property, identifier: identifier)

    // Get name
    //    If wanting a composite name including prefix, suxif, title, both names etc:
    //    NSString *contactName = CFBridgingRelease(ABRecordCopyCompositeName(person));
    let contactName = ABRecordCopyValue(person, kABPersonFirstNameProperty)

    // Get number
    var number = String()
    let numbers = ABRecordCopyValue(person, kABPersonPhoneProperty)

    for var index:CFIndex = 0; index < ABMultiValueGetCount(numbers); ++index{
        if identifier = ABMultiValueGetIdentifierAtIndex(numbers, index) {
            number = ABMultiValueCopyValueAtIndex(numbers, index)
        }
    }
}
Sam Heather
  • 1,371
  • 2
  • 17
  • 39

1 Answers1

1

Just cycle using normal numbers:

for index in 0 ..< ABMultiValueGetCount(numbers) {
matt
  • 447,615
  • 74
  • 748
  • 977
  • I get back to a different error on conversion: "'(IntegerLiteralConvertible, CFIndex)' is not convertible to 'IntegerLiteralConvertible'" – Sam Heather Jun 30 '15 at 04:35
  • 1
    You forgot to take the retained value of `numbers`. – matt Jun 30 '15 at 04:52
  • 1
    See my example here https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch18p713addressBook/ch31p973addressBook/ViewController.swift – matt Jun 30 '15 at 04:53
  • that explained it perfectly - thank you :) I didn't realise about using takeRetainedValue() – Sam Heather Jul 02 '15 at 03:25