2011-09-14 11 views
14

İşaretçiyi bir yönteme göstericiye iletmeye çalışıyorum, ancak ARC'nin bunu nasıl yaptığımla ilgili bazı sorunları var. İşte iki yöntem:Otomatik Referans Sayımı Sorun: Geri alma için yerel olmayan nesnenin __autoreleasing parametresine geçirilmesi

[self SHL_initPersonPropertyNamesWithArray:&propertyNames] : NULL; 
+0

Bu [https://stackoverflow.com/questions/8814718/handling-pointer-to-pointer-ownership-issues-in-arc?answertab=active#tab-top] adresini de kontrol edin; Şüpheler – tharinduNA

cevap

26

__strong depolama eleme Bu durum için gereklidir: Aşağıdaki komut belirir satırında

Automatic Reference Counting Issue: Passing address of non-local object to __autoreleasing parameter for write-back

: Aşağıdaki hatayı alıyorsunuz

+ (NSString *)personPropertyNameForIndex:(kSHLPersonDetailsTableRowIndex)index 
{ 
    static NSArray *propertyNames = nil; 

    (nil == propertyNames) ? 
     [self SHL_initPersonPropertyNamesWithArray:&propertyNames] : NULL; 
} 

+ (void)SHL_initPersonPropertyNamesWithArray:(NSArray **)theArray 
{ 
    *theArray = [[NSArray alloc] 
       initWithObjects:@"name", @"email", @"birthdate", @"phone", nil]; 
} 

.

+ (void)SHL_initPersonPropertyNamesWithArray:(NSArray * __strong *)theArray 

Ancak bu kod Basic Memory Management Rules takip etmez.

You own any object you create

You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).

Bunun için ne yapmak istersiniz?

+0

Şüphesiz, bu yöntem çağrıldığında bir koşullu IF'yi kullanmak yerine, üçlü bir işlemi ve ardından bir başlatma fonksiyonu kullanıyorum, ancak belki daha iyisi, C'den ziyade Objective-C dünyasına aşina olanlarla daha iyi olacağım. – Rami

İlgili konular