[英]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.