Skip to content

Instantly share code, notes, and snippets.

@benjaminsnorris
Created January 10, 2015 16:23
Show Gist options
  • Save benjaminsnorris/9336d9c16835a9dc40a1 to your computer and use it in GitHub Desktop.
Save benjaminsnorris/9336d9c16835a9dc40a1 to your computer and use it in GitHub Desktop.
Get multiple values from selected contacted
+ (NSDictionary *)getMultipleValuesForPerson:(ABRecordRef)person forProperty:(ABPropertyID)property sanitizeToNumbers:(BOOL)sanitize {
NSMutableDictionary *mutableValuesWithLabels = [NSMutableDictionary dictionary];
ABMultiValueRef values = ABRecordCopyValue(person, property);
if (values && ABMultiValueGetCount(values) > 0)
{
for (CFIndex index = 0; index < ABMultiValueGetCount(values); index++) {
NSString *label = CFBridgingRelease(ABMultiValueCopyLabelAtIndex(values, index));
NSString *value = CFBridgingRelease(ABMultiValueCopyValueAtIndex(values, index));
if (sanitize) {
value = [[value componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""];
}
[mutableValuesWithLabels setObject:value forKey:label];
}
CFRelease(values);
}
return mutableValuesWithLabels;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment