Created
March 9, 2016 08:45
-
-
Save keitaito/07fe97de694ea0575707 to your computer and use it in GitHub Desktop.
Get value from CFDictionaryRef by converting it to NSDictionary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSString *)getValueFromCFDictionaryRef { | |
// Assume you have record ID. | |
NSInteger recordID; | |
// Get a person record. | |
ABAddressBookRef addressBook = ABAddressBookCreate(); | |
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, recordID); | |
// Get addresses data from person. Watch out it's a multi-value property. | |
ABMultiValueRef addresses = ABRecordCopyValue(person, kABPersonAddressProperty); | |
// Get the first one. Convert it from CFDictionaryRef to NSDictionary. | |
NSDictionary *address = (NSDictionary *)CFBridgingRelease(ABMultiValueCopyValueAtIndex(addresses, 0)); | |
// Convert a dictionary key too, and get its value. | |
NSString *city = address[(NSString *)CFBridgingRelease(kABPersonAddressCityKey)]; | |
// Don't forget to release objects. | |
CFRelease(addresses); | |
CFRelease(addressBook); | |
return city; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment