加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用swift访问iOS中的联系人详细信息

发布时间:2020-12-14 04:51:36 所属栏目:百科 来源:网络整理
导读:使用Objective-C时,我们通常使用以下代码来获取详细信息 NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson,kABPersonFirstNameProperty); 在Swift中我尝试了以下内容 var firstName : NSString = ABRecordCopyValue(co
使用Objective-C时,我们通常使用以下代码来获取详细信息

NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson,kABPersonFirstNameProperty);

在Swift中我尝试了以下内容

var firstName : NSString = ABRecordCopyValue(contactPerson,kABPersonFirstNameProperty).takeUnretainedValue() as NSString

而且由于错误,我无法构建

Bitcast requires both operands to be pointer or neither
  %224 = bitcast %objc_object* %223 to %PSs9AnyObject_,!dbg !486
Bitcast requires both operands to be pointer or neither
  %225 = bitcast %PSs9AnyObject_ %224 to i8*,!dbg !486
LLVM ERROR: Broken function found,compilation aborted!
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1

解决方法

以下在Xcode6 beta 4中运行良好.

var firstName: NSString! = Unmanaged<CFString>.fromOpaque(ABRecordCopyValue(record,kABPersonFirstNameProperty).toOpaque()).takeUnretainedValue().__conversion()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读