自动ARC转换后:将保留的对象分配给不安全的属性;对象将在分配后释放 [英] After Auto-ARC Conversion: Assigning retained object to unsafe property; object will be released after assignment

查看:93
本文介绍了自动ARC转换后:将保留的对象分配给不安全的属性;对象将在分配后释放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用Xcode的自动重构将旧项目转换为ARC。

I just converted an old project to ARC using Xcode's automatic refactoring.

@property (nonatomic, retain) NSMutableArray *cards;

被替换为:

@property (nonatomic) NSMutableArray *cards;

这是有道理的,因为我读到的是强是默认状态。但是,以下行给出了标题中的错误:

This makes sense because what I've read is that "strong" is the default state. However, the following line is giving me the error in the title:

self.cards = [[NSMutableArray alloc] initWithCapacity:54];

错误是通过添加 strong 来解决的曾经保留过的地方:

The error is solved by adding strong back in where retain used to be:

@property (nonatomic, strong) NSMutableArray *cards;

但是......如果我需要返回并将进入每个@property声明保留 ...为什么ARC重构将它们全部删除?

However... if I need to go back and put strong in to every @property declaration that was retain... why did the ARC refactoring remove them all?

推荐答案

我遇到了同样的警告并打开了技术支持事件。工程师验证默认值已从分配更改为强,原因是ARC内的一致性。

I've run into the same warning and opened an Technical Support Incident. The engineer verified that the default was changed from "assign" to "strong" for reasons of consistency within ARC.

他说这两个警告并且文档是错误的并且将被修复。在此之前,我会完全避免隐式默认

He said both the warning and the documentation are wrong and will be fixed. Until that is done, I would avoid the implicit default altogether!

明确添加强(如BJ荷马建议的那样)是一种安全的方法使警告静音并兼容。但是,不要假设默认情况下不返回属性。总是把弱或分配放在那里。

Explicitly adding "strong" (as BJ Homer suggested) is a safe way to silence the warning and be compatible. But don't assume properties to be unretained by default. Always put "weak" or "assign" there, too.

编辑: clang文档现在正式记录了这一变化。该警告已已修复

The clang documentation now officially documents this change. The warning has been fixed.

编辑2:Xcode 4.4显然包括修复。

Edit 2: Xcode 4.4 apparently includes the fix.

这篇关于自动ARC转换后:将保留的对象分配给不安全的属性;对象将在分配后释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆