Xcode 4.2.1 ARC 问题

发布于 2025-01-05 02:24:54 字数 351 浏览 1 评论 0原文

仅限 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有你 2025-01-12 02:24:54

这不是特定于 Beta 的 Xcode 4.2.1 具有相同的行为(Beta 处于 NDA 之下,只能在 Apple 的开发者论坛中合法讨论):

Strong 是 ivar 的默认设置。对于 ivars,如果您需要 __unsafe_unretained__weak,则必须指定。

在属性声明中指定属性始终是最佳实践。最快速浮现在脑海中的一个示例是 UILabel 属性文本,定义为:

@property(nonatomic,copy) NSString *text; // default is nil

在本例中,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 ivars. 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:

@property(nonatomic,copy) NSString *text; // default is nil

In this example the copy attribute tells me I can pass an NSMutableString 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文