0

Currently I have a crash when reading phone No. with empty label:

fatal error: unexpectedly found nil while unwrapping an Optional value

if let phones: ABMultiValueRef = ABRecordCopyValue(person,
    kABPersonPhoneProperty)?.takeRetainedValue(){

        for counter in 0..<ABMultiValueGetCount(phones){

            let label = ABMultiValueCopyLabelAtIndex(phones,
                counter).takeRetainedValue() as String
            let phone = ABMultiValueCopyValueAtIndex(phones,
                counter).takeRetainedValue() as! String

        }
}

I tried to read label as:

let label = ABMultiValueCopyLabelAtIndex(phones,
                        counter).takeRetainedValue()  as? String ?? ""

but result is the same.

Shmidt
  • 16,436
  • 18
  • 88
  • 136

2 Answers2

0

I didn't test but this should work

if let phoneTest = ABMultiValueCopyValueAtIndex(phones, counter).takeRetainedValue()
{
    let phone = phoneTest as String
}
Icaro
  • 14,585
  • 6
  • 60
  • 75
0
let label = ABMultiValueCopyLabelAtIndex(phones,
                        counter).takeRetainedValue()  as? String ?? ""

is the right way to do it. I had some other bug in my app, that's why I thought this solution doesn't work.

Shmidt
  • 16,436
  • 18
  • 88
  • 136