0

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);

その後、値を使用しますが、唯一のことは、値を解放する必要があるかどうかわからないことです。

メモリ管理をよりよく理解するのに役立つ、または正しい方向を示す答えをいただければ幸いです。

ありがとうございました!

4

1 に答える 1

5

Core Foundationの経験則では、名前に含まれる関数CopyまたはCreate名前に含まれる関数は、リリースする責任のあるオブジェクトを返します。AppleのCoreFoundationのメモリ管理ガイドでは、これについてもう少し詳しく説明しています。

于 2010-11-22T04:06:04.823 に答える