ios - swift : Issue with accessing CFDictionaryRef for ABAddressBookRef

标签 ios iphone swift ios8 abaddressbook

我在 ObjC 中收集了联系人的地址信息,

ABMultiValueRef addressProperty = ABRecordCopyValue(contactRef, kABPersonAddressProperty);
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addressProperty, 0);
   if(dict)
   {
     NSString *street = (NSString *)CFDictionaryGetValue(dict, kABPersonAddressStreetKey);
   }

因此,等效的 Swift 代码是,

let addressProperty : ABMultiValueRef = ABRecordCopyValue(contactRef, kABPersonAddressProperty).takeUnretainedValue() as ABMultiValueRef

    if let dict : CFDictionaryRef = ABMultiValueCopyValueAtIndex(addressProperty, 0).takeUnretainedValue() as? CFDictionaryRef
    {
     let street = CFDictionaryGetValue(dict,kABPersonAddressStreetKey)
    // Stuck here, among  CFString!, UnsafePointer<Void>, CFDictionaryRef ...
    }

我将如何获取街道和其他类似信息?

最佳答案

你可以使用NSDictionary来代替吗? (未测试)

if let dict : NSDictionary = ABMultiValueCopyValueAtIndex(addressProperty, 0).takeUnretainedValue() as? NSDictionary
{
 let street = dict[kABPersonAddressStreetKey]
}

关于ios - swift : Issue with accessing CFDictionaryRef for ABAddressBookRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25542404/

相关文章:

iphone - 我应该将 UIBarButtonItem 设置为多宽才能制作方形按钮?

ios - 如何在可编码结构中使用计算属性(swift)

ios - iPhone播放特定的播放列表/iMix

iPhone 将图像发布到 Facebook Feed

iOS UIPickerView 自定义行 View 宽度错误

ios - 基本 iCloud 键值存储测试失败

ios - 我的球在我的 iPhone 上反弹得比在我的模拟器 swift spritekit 上高

ios - 核心数据删除规则,删除所有关系和实体(很多)

ios - 调试 Xcode 程序或查看输出日志

iOS AssetLibrary 存储指针