Xcode 4.2.1 ARC 问题
仅限 iOS5 且启用 ARC 的项目可在 Xcode 4.3.1 beta 上编译。在4.2.1上编译时。 LLVM 发出如下警告:
“ARC 禁止将 Objective-C 对象的属性与 未指定的所有权或存储属性”
因此属性定义如下所示:
@property (nonatomic) NSObject* object
在构建设置中启用了 ARC。添加强属性可以修复此警告,但这应该是默认,对吗?
Xcode 版本之间有区别吗处理这些属性默认
值 ? 安迪
a project which is iOS5 only and ARC enabled compiles on Xcode 4.3.1 beta. When compiling on 4.2.1. LLVM is throwing warnings like these:
"ARC forbids synthesizing a property of an Objective-C object with
unspecified ownership or storage attribute"
So the property definitions looks like this:
@property (nonatomic) NSObject* object
ARC is enabled in Build Settings. Adding a strong attribute fixes this warning but this should be default right?
Is there a difference between the Xcode versions in handling those property defaults?
Thanks
Andi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是特定于 Beta 的 Xcode 4.2.1 具有相同的行为(Beta 处于 NDA 之下,只能在 Apple 的开发者论坛中合法讨论):
Strong 是
ivar
的默认设置。对于 ivars,如果您需要__unsafe_unretained
或__weak
,则必须指定。在属性声明中指定属性始终是最佳实践。最快速浮现在脑海中的一个示例是
UILabel
属性文本,定义为:在本例中,
copy
属性告诉我可以传递一个NSMutableString
引用标签,它将制作一个副本,我可以继续改变字符串,标签将保持不变。行为被明确定义。我怀疑明确定义的行为是 ARC 编译器强制您指定存储属性的最重要原因。请记住,新的运行时消除了为属性声明 ivars 和为访问器方法声明
@synthesize
的需要,可以想象,如果您不小心保留了委托,则属性声明可能是您会注意到的唯一点。还要考虑项目中的一些类可能已从 ARC 中排除的可能性,在这些情况下,内部实现对 ARC 完全不透明。
This is not beta specific Xcode 4.2.1 has the same behavior (betas are under NDA and should only legally be discussed in apple's developer forums):
Strong is the default setting for
ivar
s. For ivars if you want__unsafe_unretained
or__weak
you must specify.It has always been best practice to specify attributes in property declarations. One example that pops most quickly to mind is the
UILabel
property text, defined as:In this example the
copy
attribute tells me I can pass anNSMutableString
reference to the label and it will make a copy and I can go on mutating the string the label will remain the same. The behavior is clearly defined.And I suspect it's the clearly defined behavior which was the most prominent reason that the ARC compiler forces you to specify storage attributes. Remember with the new runtimes eliminating the need to declare ivars for properties and
@synthesize
for accessor methods, it's conceivable that the property declaration is the only point you will notice if you accidentally retained a delegate.Also consider the possibility that a few classes in a project may have been excluded from ARC in these cases there internal implementation would be completely opaque to ARC.