Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 660
Colateral Avatar asked Aug 05 '15 14:08

Colateral


1 Answers

Try this:

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

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

like image 90
tounaobun Avatar answered Nov 14 '22 22:11

tounaobun