CFRelease
需要一个非 NULL 指针。您可以使用if
语句进行检查,但更容易简单地释放或自动释放friendLastName
:
CFStringRef lastNameRef = ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
NSString *friendLastName = (NSString*)lastNameRef;
// use friendLastName
[friendLastName release];
或者
CFStringRef lastNameRef = ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
NSString *friendLastName = (NSString*)lastNameRef;
[friendLastName autorelease];
// use friendLastName
由于您似乎没有使用lastNameRef
,您也可以内联该变量:
NSString *friendLastName = (NSString*)ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
// use friendLastName
[friendLastName release];
或者
NSString *friendLastName = (NSString*)ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
[friendLastName autorelease];
// use friendLastName