Colateral
Colateral

Reputation: 1801

How to convert Unmanaged<CFString> to NSString?

My application is dealing with contacts data.

The phone label is retrieved as following

let locPhoneLabel : NSString = (ABMultiValueCopyLabelAtIndex(phones, numberIndex) != nil) ? ABMultiValueCopyLabelAtIndex(phones, numberIndex).takeUnretainedValue() as CFStringRef : ""

let phoneLabel:Unmanaged<CFString> = ABAddressBookCopyLocalizedLabel(locPhoneLabel)

I don't know how to convert phoneLabel to NSString?

Upvotes: 5

Views: 3650

Answers (2)

Paul T.
Paul T.

Reputation: 5038

For me it only helped:

let locLabel : CFStringRef = (ABMultiValueCopyLabelAtIndex(phoneNumbers, i) != nil) ? (ABMultiValueCopyLabelAtIndex(phoneNumbers, i).takeUnretainedValue()) as CFStringRef : ""
let noteForThisNumber = String (ABAddressBookCopyLocalizedLabel(locLabel).takeRetainedValue())

Upvotes: 0

tounaobun
tounaobun

Reputation: 14857

Try this:

let phoneLabel = ABAddressBookCopyLocalizedLabel(locPhoneLabel)
.takeRetainedValue() as? NSString

There is a great post here if you are interested.Unmanaged from NSHipster.

Upvotes: 13

Related Questions