这是我的代码:
[ NSUInteger peopleCounter = 0; //set a initial value as ZERO.
//Create custom Contacts list
for (peopleCounter = 0; peopleCounter < [arrayOfAllPeople count]; peopleCounter++) {
ABRecordRef thisPerson = (__bridge ABRecordRef) [arrayOfAllPeople objectAtIndex:peopleCounter]; // get every person record one by one.
NSString *name = (__bridge NSString *) ABRecordCopyCompositeName(thisPerson); //get a person name
ABMultiValueRef number = ABRecordCopyValue(thisPerson, kABPersonPhoneProperty); //get a person number
//optimize a phone numbers
for (NSUInteger emailCounter = 0; emailCounter < ABMultiValueGetCount(number); emailCounter++) {
NSString *email = (__bridge NSString *)ABMultiValueCopyValueAtIndex(number, emailCounter);
][1]
答案 0 :(得分:0)
当您使用名称为ABRecordCopyCompositeName
的 copy 的方法返回Core Foundation对象(如CFStringRef
时)时,您应该考虑内存管理,因为ARC不起作用,除非你告诉它应该如何处理情况。
在您的情况下,您应该使用__bridge_transfer
代替__bridge
:
NSString *name = (__bridge_transfer NSString *) ABRecordCopyCompositeName(thisPerson); //get a person name
因此ABRecordCopyCompositeName
结果生命周期将与name
变量生命周期相关联。
在您的示例中也注意ABMultiValueCopyValueAtIndex
。