如何为 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/