2014-08-28 24 views
2

心中已经收集在ObjC联系人的地址信息,斯威夫特:问题与访问CFDictionaryRef为ABAddressBookRef

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

所以,相当于银行代码是,

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 ... 
    } 

我怎么会获取街道和其他类似的信息?

回答

2

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

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

噢是的,它是工作,我已经用dict .__ conversion(),它将CFDictionaryRef转换为NSDictionary,但现在我直接去NSDictionary。谢谢 – BaSha 2014-08-29 05:19:59