2012-03-12 2 views
1

この方法をARCに書き換えるにはどうすればよいですか?Obj-C ARC:アレイ/セットからオブジェクトを削除し、それをオートレリースオブジェクトとして返す方法はありますか?

- (KTThumbView *)dequeueReusableThumbView 
{ 
    KTThumbView *thumbView = [reusableThumbViews_ anyObject]; 
    if (thumbView != nil) { 
     // The only object retaining the view is the 
     // reusableThumbViews set, so we retain/autorelease 
     // it before returning it so that it's not immediately 
     // deallocated when removed form the set. 
     [[thumbView retain] autorelease]; 
     [reusableThumbViews_ removeObject:thumbView]; 
    } 
    return thumbView; 
} 

自動ARCの移行では、私は、このエラーを与える:

[rewriter] it is not safe to remove an unused 'autorelease' message; its receiver may be destroyed immediately 
+0

chdckこのリンクhttp://clang.llvm.org/docs/AutomaticReferenceCounting.html#objects.operands.retained_returns –

+0

ARCは必要に応じて 'autorelease'を追加して' thumbView'の世話をします。あなたはそれをそのまま残す必要があります。単純に 'thumbView'を返します。私の変数をこのように残すのは少し難しかったです。私はARCに頼ることができます;) – thesummersign

答えて

1

ちょうど[[thumbView retain] autorelease];行を削除します。最初の行は、必要に応じてその周りを保証する強力な参照を作成します。

関連する問題