簡體   English   中英

Obj-C ARC:如何從數組/集中刪除對象,然后將其作為自動釋放的對象返回?

[英]Obj-C ARC: How to remove an object from an array/set and then return it as an autoreleased object?

如何為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

只需刪除[[thumbView retain] autorelease]; 線。 第一行將作為有力的參考,以確保在需要時在其周圍進行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM