objective-c - Objective-C 弧 : How to remove an object from an array/set and then return it as an autoreleased object?

标签 objective-c ios cocoa-touch ios5 automatic-ref-counting

如何为 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]; 行。第一行将提供一个强有力的引用,保证其在需要时出现。

关于objective-c - Objective-C 弧 : How to remove an object from an array/set and then return it as an autoreleased object?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9661720/

相关文章:

ios - 使用LFLiveKit捕获屏幕并流到rtmp服务器

html - 如何在页脚中正确定位 iOS 音频播放器?

iphone - 自定义 UINavigationBar 的最惯用的 iOS5 方式?

iphone - Mac 和 iPhone 上的共享模型

ios - 如何检查 PDF 是否有效并且可以在 UIWebView 中打开

ios - 带有文本第一个字符的 UITableView

objective-c - 在 OS X 上打开 NSImage 时从 EXIF 读取相机数据

iphone - 使用indexOfObject :inSortedRange:options:usingComparator:对数组进行二分搜索

ios - 当 TableView 滚动时如何阻止 uitableviewcell 中的 uipangesturerecognizer

ios - 如何显示流式 Apple Music 的专辑插图?