Zeb*_*ebs 0 iphone cocoa-touch memory-management cfstring addressbook
我正在使用Apple提供的API从AddressBook中读取记录.
我仍在考虑内存管理,所以CFStrings此刻让我感到困惑.
这就是我获取属性的方式:
//Get Basic properties
NSString* firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSNumber* record = [NSNumber numberWithInt:ABRecordGetRecordID(person)];
//Build Full Name
NSString* fullName=[self fullNameWith:firstName and:lastName];
//Get Phone number and Label
ABMultiValueRef phone = ABRecordCopyValue(person, property);
//Turn identifier into index
CFIndex index = ABMultiValueGetIndexForIdentifier(phone, identifier);
//Get the value and the label using the index
NSString *value =(NSString *)ABMultiValueCopyValueAtIndex(phone, index);
CFStringRef label = ABMultiValueCopyLabelAtIndex(phone, index);
//Get the localized value of hte label
NSString * localizedLabel = (NSString *)ABAddressBookCopyLocalizedLabel(label);
Run Code Online (Sandbox Code Playgroud)
之后我使用这些值,唯一的事情是我不知道是否应该释放它们.
我希望得到一个答案,这也有助于我更好地理解记忆管理,或者指出我正确的方向.
谢谢!