xcode 什么是 ARC 限制,我该如何移除它们?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9920929/
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
What are ARC restrictions, and how can I remove them?
提问by neuromancer
I just downloaded an Xcode project, and I get all these errors about "ARC Restrictions." What are these, and how can I remove them?
我刚刚下载了一个 Xcode 项目,我收到了关于“ARC 限制”的所有这些错误。这些是什么,我该如何删除它们?
回答by Andy Friese
There are basically two versions of memory management in objective-c. ARC and... well, "Not ARC" :-) You probably downloaded a project, which doesn't use ARC already. Simplest way of resolving your problem is to instruct the compiler to treat your sources as "Not ARC". Explained here.
Objective-c 中基本上有两个版本的内存管理。ARC 和...好吧,“不是 ARC” :-) 您可能下载了一个尚未使用 ARC 的项目。解决您的问题的最简单方法是指示编译器将您的源代码视为“非 ARC”。在这里解释。
And hereis a good tutorial that should get you started with ARC.
而这里是一个很好的教程,应该让您开始使用ARC。
回答by Sunil Pandey
ARC automatically keep track of memory release and retain so you can not release and retain any memory manually.
ARC 自动跟踪内存释放和保留,因此您无法手动释放和保留任何内存。
ARC also doesn't allow any method to be get called at compile time which prototype is not declared in interfaces.
ARC 也不允许在编译时调用任何未在接口中声明原型的方法。
It has also introduced new @autoreleasepool block. so it doesn't not allow older autorelease of an object automatically
它还引入了新的@autoreleasepool 块。所以它不允许自动释放旧的对象
However it has allowed dealloc method to be written, but it doesn't allowed [super dealloc] to be get called.
但是,它允许编写 dealloc 方法,但不允许调用 [super dealloc]。
There are much more written about ARC at this blogyou can checkt it here
You can covert your project to ARC using xcode in following way. Go to Edit -> Refactor -> Convert to objective c arc.
您可以通过以下方式使用 xcode 将您的项目转换为 ARC。转到编辑 -> 重构 -> 转换为目标 c 弧。
However it has some compatibility issue with git repository so it does not convert when .git folders are there in projects. so you will have to remove it first and then convert it. check this link
但是它与 git 存储库存在一些兼容性问题,因此当项目中存在 .git 文件夹时它不会转换。所以你必须先删除它,然后再转换它。检查此链接