iosswiftaddressbookaddressbookuiabmultivalue

"Binary operator '<' cannot be applied to two CFIndex operands" - choosing a phone number from ABMultiValue (Address Book)


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)
        }
    }
}

Solution

  • Just cycle using normal numbers:

    for index in 0 ..< ABMultiValueGetCount(numbers) {