[英]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? 我不知道如何将phoneLabel转换为NSString?
Try this: 尝试这个:
let phoneLabel = ABAddressBookCopyLocalizedLabel(locPhoneLabel)
.takeRetainedValue() as? NSString
There is a great post here if you are interested. 如果您有兴趣,这里有一篇很棒的帖子。 Unmanaged from NSHipster .
不受NSHipster管理 。
For me it only helped: 对我来说它只有帮助:
let locLabel : CFStringRef = (ABMultiValueCopyLabelAtIndex(phoneNumbers, i) != nil) ? (ABMultiValueCopyLabelAtIndex(phoneNumbers, i).takeUnretainedValue()) as CFStringRef : ""
let noteForThisNumber = String (ABAddressBookCopyLocalizedLabel(locLabel).takeRetainedValue())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.