Swift:访问ABAddressBookRef的CFDictionaryRef时遇到问题

时间:2014-08-28 06:47:38

标签: 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 ...
    }

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

1 个答案:

答案 0 :(得分:2)

您可以使用NSDictionary吗? (未经测试)

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