繁体   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