我已经在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]
}