ios - 使用 swift 在 iOS 中访问联系人详细信息

标签 ios nsstring swift abaddressbook

在使用 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

最佳答案

这适用于 Xcode 6 GM

let firstName = ABRecordCopyValue(contactRecord, kABPersonFirstNameProperty).takeRetainedValue() as String

比上面的例子稍微简洁一些。

关于ios - 使用 swift 在 iOS 中访问联系人详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24902163/

相关文章:

nsstring - 如何将 NSString 转换为 char?

ios - NSData 到 NSString 编码返回乱码

swift - 达到最大时间戳计数,不会记录更多事件 Xcode

ios - 在 Swift 中捕获 [weak self] 的 Realm 通知

ios - 在其扩展VS Struct中添加协议(protocol)的功能实现,符合协议(protocol)并实现功能

ios - UIContextualAction 显示 UIMenu

ios - 使用粒子创建特殊图形?

php date() 没有收到年、月、日 : NSDate to php

objective-c - 在 ObjC(iOS) 中将文本从 "HELLO, WORLD. HOW ARE YOU?"格式化为 "Hello, world. How are you?"?

swift - Xcode Swift编译报错import name too long