如何将Unmanaged <cfstring>转换为NSString?

时间:2015-08-05 14:05:01

标签: ios swift cfstring

我的应用程序正在处理联系人数据。

手机标签检索如下

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

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

我不知道如何将phoneLabel转换为NSString?

2 个答案:

答案 0 :(得分:9)

试试这个:

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

如果您有兴趣,可以在此发帖。Unmanaged from NSHipster

答案 1 :(得分:0)

对我来说它只有帮助:

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