How to convert unmanaged <CFString> to NSString?

My application deals with contact data.

The phone tag is retrieved as follows

let locPhoneLabel : NSString = (ABMultiValueCopyLabelAtIndex(phones, numberIndex) != nil) ? ABMultiValueCopyLabelAtIndex(phones, numberIndex).takeUnretainedValue() as CFStringRef : "" let phoneLabel:Unmanaged<CFString> = ABAddressBookCopyLocalizedLabel(locPhoneLabel) 

I do not know how to convert phoneLabel to NSString?

+4
source share
2 answers

Try the following:

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

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

+9
source

For me it helped:

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

All Articles