xcode 应用程序转换为 ARC,现在收到有关我的属性的警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9608534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
App converted to ARC, now getting warnings about my properties
提问by Nic Hubbard
I just converted my app to ARC
, and while it builds fine, I get like 600 warnings, all pertaining to my properties. Such as:
我刚刚将我的应用程序转换为ARC
,虽然它构建良好,但我收到了 600 条警告,所有这些都与我的属性有关。如:
Default property attribute 'assign' not appropriate for non-gc object
No 'assign', 'retain' or 'copy' attribute is specified - 'assign' is assumed
默认属性属性“assign”不适用于非 gc 对象
未指定“分配”、“保留”或“复制”属性 - 假定为“分配”
After Xcode converted my code, here is what my properties look like:
在 Xcode 转换我的代码后,我的属性如下所示:
@property (nonatomic) EKEventStore *eventStore;
@property (nonatomic) EKCalendar *defaultCalendar;
@property (nonatomic) UIActionSheet *currentActionSheet;
@property (nonatomic) UILabel *noEventLabel;
Someone talked about needing to add strong
to all of these. Is this the case? Did Xcode forget to add something?
有人谈到需要添加strong
所有这些。是这种情况吗?Xcode 是不是忘记添加一些东西了?
回答by matt
ARC is right. You cannot have nomemory-management qualifer; you mustsay assign, retain (or strong which is the same thing), or weak.
ARC是对的。你不能没有内存管理限定符;你必须说分配、保留(或强这是同一件事)或弱。
Previously, assign was the default. But that is probably not what you want, because is it is the worst possible option - it is an old-style non-ARC weak reference. You either want a smart ARC weak reference (goes to nil when the object goes out of existence) or a strong reference (memory-managed for you by ARC).
以前,assign 是默认设置。但这可能不是您想要的,因为它是最糟糕的选择 - 它是旧式的非 ARC 弱引用。您要么想要一个智能 ARC 弱引用(当对象不存在时变为 nil)或一个强引用(由 ARC 为您管理内存)。
回答by matt
Sorry to add a second answer, but this turns out to be more intricate than I thought. It turns out that you're seeing a changed behavior (perhaps a bug?) in Xcode 4.3.
很抱歉添加第二个答案,但事实证明这比我想象的要复杂。事实证明,您在 Xcode 4.3 中看到了改变的行为(也许是一个错误?)。
In Xcode 4.2, the converter would have offered to change (nonatomic, retain)
to (nonatomic, strong)
. But in Xcode 4.3, it offers to change it to (nonatomic)
; I guess if you don't want that, changing retain
to strong
is up to you before converting.
在 Xcode 4.2 中,转换器会提供更改(nonatomic, retain)
为(nonatomic, strong)
. 但是在 Xcode 4.3 中,它提供将其更改为(nonatomic)
; 我想,如果你不希望出现这种情况,换retain
到strong
是给你转换之前。
On the other hand, in Xcode 4.2, (nonatomic)
alone was absolutely illegal for a synthesized property; in Xcode 4.3, it is not: you get a warning, but it assumes you mean assign
and so it isn't illegal.
另一方面,在 Xcode 4.2 中,(nonatomic)
单独使用合成属性是绝对非法的;在 Xcode 4.3 中,它不是:您收到警告,但它假定您的意思assign
,因此它不是非法的。
So there's been a change in how ARC works in LLVM 3.1 and an accompanying change in the Xcode 4.3 ARC converter.
所以 ARC 在 LLVM 3.1 中的工作方式发生了变化,Xcode 4.3 ARC 转换器也随之发生了变化。
回答by user4951
I think the answers are wrong.
我认为答案是错误的。
In Xcode 4.3 you get a warning. However, it assumes you mean RETAIN. Retain is the new default for codes under ARC. Someone told me that xcode is fixing this.
在 Xcode 4.3 中,您会收到警告。但是,它假定您的意思是保留。Retain 是 ARC 下代码的新默认值。有人告诉我 xcode 正在解决这个问题。
Please correct me if I am wrong.
如果我错了,请纠正我。