关于Xcode4.2内存管理,需要澄清
假设创建了一个启用了 ARC 的新项目
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
,并声明了以下声明,
@property (nonatomic) NSString *classDescription;
为什么会
@synthesize classDescription;
出错
"Existing ivar 'classDescription' for unsafe_unretained propery 'classDescription must be _unsafe_unretained"
我认为使用 Xcode 4.2 版本,无需保留,需要发布。 是这样吗不正确?
请澄清
Assuming a new project with ARC enabled is created
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
and the following declaration
@property (nonatomic) NSString *classDescription;
Why would
@synthesize classDescription;
error out with
"Existing ivar 'classDescription' for unsafe_unretained propery 'classDescription must be _unsafe_unretained"
I thought that with Version 4.2 of Xcode, no retains, releases are needed. Is this not correct?
Please clarify
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要将其设为
strong
属性,以便 ARC 知道它应该保留该对象。You need to make it a
strong
property so that ARC knows it should retain the object.如果您使用自动引用计数,则不需要保留/释放。这是现有项目还是新项目?新项目应默认启用 ARC。
No retains/releases are needed if you are using Automatic Reference Counting. Is this an existing project or new project? New projects should have ARC enabled by default.
如果您的项目是在 Xcode 4.2 之前创建的,那么您可以通过转到“构建设置”、搜索“Objective-C++ 自动引用计数”并勾选该框来启用它。
If your project was made before Xcode 4.2, then you can enable it by going to Build Settings, search for Objective-C++ Automatic Reference Counting and tick the box.