سؤال

أقرأ السجلات من دفتر العناوين باستخدام APP API.

ما زلت أحصل على رأسي حول إدارة الذاكرة وهكذا 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);

بعد ذلك أستخدم القيم ، الشيء الوحيد هو أنني لا أعرف ما إذا كان ينبغي علي إطلاقها أم لا.

سأقدر إجابة ساعدتني أيضًا في فهم إدارة الذاكرة بشكل أفضل أو تشيرني إلى الاتجاه الصحيح.

شكرًا لك!

هل كانت مفيدة؟

المحلول

قاعدة الإبهام للمؤسسة الأساسية هي أن أي وظائف تتضمن Copy أو Create سوف يعيد اسمهم كائنًا مسؤولاً عن إطلاقه. تفاح دليل إدارة الذاكرة للمؤسسة الأساسية يشرح هذا بمزيد من التفاصيل.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top