user2392671
user2392671

Reputation: 61

Call to function 'ABRecordCopyValue' returns a corefoundation object with a +1 retain count

I have following code in my project

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    [popContactsForm dismissPopoverAnimated:YES];

    [ssemailvc setName: (NSString *)ABRecordCopyValue(person,kABPersonFirstNameProperty)];        
    ABMultiValueRef emails = (NSString *)ABRecordCopyValue(person,kABPersonEmailProperty);


    if (ABMultiValueGetCount(emails)>0) {
        [ssemailvc setEmail:(NSString *)ABMultiValueCopyValueAtIndex(emails,0)];
    }else [ssemailvc setEmail:@""];

    CFRelease(emails);


    [peoplePicker dismissModalViewControllerAnimated:YES];      
    [popEmailForm setPopoverContentSize:CGSizeMake(350.0, 225.0)];

    return NO;
}

I am gettings following warnings

1.call to function 'ABRecordCopyValue' returns a corefoundation object with a +1 retain count 2.object leaked:allocated object is not referenced later in the execution and has a retain count of +1

Please tell me how to overcome this problem

Upvotes: 3

Views: 2053

Answers (2)

Deepesh Gairola
Deepesh Gairola

Reputation: 1242

The reason you're seeing the warning is that ABRecordCopyValue returns a CFStringRef with +1 retain count.

Try

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person {

[popContactsForm dismissPopoverAnimated:YES];

CFStringRef strLname = ABRecordCopyValue(person, kABPersonLastNameProperty);
[ssemailvc setName: (NSString *) strLname];  

if(strLname){
CFRelease(strLname);
}

ABMultiValueRef emails = (NSString *)ABRecordCopyValue(person,kABPersonEmailProperty);


if (ABMultiValueGetCount(emails)>0) {
    [ssemailvc setEmail:(NSString *)ABMultiValueCopyValueAtIndex(emails,0)];
}else [ssemailvc setEmail:@""];

if(emails){
CFRelease(emails);
}

[peoplePicker dismissModalViewControllerAnimated:YES];      
[popEmailForm setPopoverContentSize:CGSizeMake(350.0, 225.0)];

return NO;
}

Upvotes: 1

justin
justin

Reputation: 104698

If using ARC, you can use a bridge cast:

CFStringRef name = (CFStringRef)ABRecordCopyValue(person,kABPersonFirstNameProperty);
[ssemailvc setName:(__bridge NSString*)name];
CFRelease(name);

or a bridge transfer:

NSString * name = (__bridge_transfer NSString *)ABRecordCopyValue(person,kABPersonFirstNameProperty);
[ssemailvc setName:name];

If you are using MRC:

CFStringRef name = (CFStringRef)ABRecordCopyValue(person,kABPersonFirstNameProperty);
[ssemailvc setName:(NSString*)name];
CFRelease(name);

Upvotes: 6

Related Questions