我的项目中有以下代码 - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { [popContactsForm dismissPopoverAnimated:YES]; [ssemailvc set
- (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; }
我收到了警告
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
请告诉我如何克服这个问题
如果使用ARC,则可以使用桥接转换:CFStringRef name = (CFStringRef)ABRecordCopyValue(person,kABPersonFirstNameProperty); [ssemailvc setName:(__bridge NSString*)name]; CFRelease(name);
或桥接转移:
NSString * name = (__bridge_transfer NSString *)ABRecordCopyValue(person,kABPersonFirstNameProperty); [ssemailvc setName:name];
如果您使用的是MRC:
CFStringRef name = (CFStringRef)ABRecordCopyValue(person,kABPersonFirstNameProperty); [ssemailvc setName:(NSString*)name]; CFRelease(name);