Question

I am able to retrieve properties from an ABRecord easily. Ie:

NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

But I am struggling to find a way to retrieve the value of CFStringRef constants from the record. For instance, how would I assign an NSString to the value of the person records kABPersonFatherLabel? (Ie the records fathers/mother name label)

Thanks for any assistance

Was it helpful?

Solution 2

Nevermind, i've found the solution. For anyone else looking for a solution, see below:

        ABMultiValueRef relatedNames = ABRecordCopyValue(person, kABPersonRelatedNamesProperty);
        NSMutableArray *relatedNameList = [[[NSMutableArray alloc] init] autorelease];
        NSDictionary *dic = [[[NSMutableDictionary alloc] init] autorelease];

        for(CFIndex j = 0; j < ABMultiValueGetCount(relatedNames); j++)
        {
            NSString *relatedNameLabel = [(NSString*)ABMultiValueCopyLabelAtIndex(relatedNames, j) autorelease];
            if ([relatedNameLabel isEqualToString:(NSString *)kABPersonFatherLabel])
            {
                relatedNameString = @"";
            }
            if (relatedNameLabel == nil)
            {
                relatedNameLabel = @"";
            }               
            NSString *relatedNameString = [(NSString*)ABMultiValueCopyValueAtIndex(relatedNames, j) autorelease];
            if (relatedNameString == nil)
            {
                relatedNameString = @"";
            }
            // Add the object to the dictionary
            [dic setValue:(NSString *)relatedNameString forKey:relatedNameLabel];
        }           

You can then access the values from the dictionary by passing the CFStringRef constants (after casting to NSString)

NSString *father = [dic objectForKey:(NSString *)kABPersonFatherLabel];

NSLog( @"%@", father );

OTHER TIPS

Like this:

NSString *fatherLabel = (NSString *)kABPersonFatherLabel;

NSString is “toll-free bridged” with its Core Foundation counterpart, CFStringRef. See “Toll-Free Bridging” for more information on toll-free bridging.

There are a number of data types in the Core Foundation framework and the Foundation framework that can be used interchangeably. This capability, called toll-free bridging, means that you can use the same data type as the parameter to a Core Foundation function call or as the receiver of an Objective-C message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top