ios 如何在 Xcode 4.2 中启用 ARC 项目范围
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7476692/
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
How do you enable ARC project-wide in Xcode 4.2
提问by Alpinista
I have an iOS app that I want to convert to using ARC. I would just use the migration tool, but it errors out for me consistently during the preview phase.
我有一个 iOS 应用程序,我想转换为使用ARC。我只会使用迁移工具,但它在预览阶段始终为我出错。
I know I can use the -fobjc-arc
compiler directive on a file-by-file basis, but I want to enable ARCon the entire project, then turn off individual classes using -fno-objc-arc
.
我知道我可以-fobjc-arc
逐个文件地使用编译器指令,但我想在整个项目中启用ARC,然后使用-fno-objc-arc
.
New projects in 4.2 can use ARC by default, so there must be a switch somewhere.
4.2新项目默认可以使用ARC,所以一定要在某处有个开关。
Can anyone help me to convert the project to ARC
谁能帮我将项目转换为 ARC
回答by RyanG
"ARC is available in Xcode 4.2, currently in beta, and only when compiling with Clang (a.k.a. "Apple LLVM compiler"). The setting is called, obviously enough, "Objective-C Automatic Reference Counting". Turn it on, and off you go.
If you're working on existing code, changing this setting will produce an enormous quantity of errors. ARC not only manages memory for you, but it forbids you from trying to do it yourself. It's illegal to manually send retain/release/autorelease when using ARC. Since normal non-ARC Cocoa code is littered with this stuff, you'll get a lot of errors.
Fortunately, Xcode offers a tool to convert existing code. Select Edit -> Refactor... -> Convert to Objective-C ARC... and Xcode will guide you through converting your code. Although there may be some situations where it needs help figuring out what to do, the process should be largely automatic."
“ARC 在 Xcode 4.2 中可用,目前处于测试阶段,并且仅在使用 Clang(又名“Apple LLVM 编译器”)进行编译时可用。显然,该设置被称为“Objective-C 自动引用计数”。打开和关闭它你走。
如果您正在处理现有代码,更改此设置将产生大量错误。ARC 不仅为您管理内存,而且禁止您尝试自己做。使用ARC时手动发送retain/release/autorelease是非法的。由于普通的非 ARC Cocoa 代码充斥着这些东西,你会得到很多错误。
幸运的是,Xcode 提供了一个工具来转换现有代码。选择 Edit -> Refactor... -> Convert to Objective-C ARC...,Xcode 将指导您完成代码的转换。尽管在某些情况下它可能需要帮助弄清楚该怎么做,但该过程应该在很大程度上是自动的。”
I took that from this link, helped me a lot: http://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html
我从这个链接中得到了它,对我帮助很大:http: //www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html
回答by Alpinista
Select your project or target and then go to Build Settingsand under the section Apple LLVM compiler 3.0 - Languageyou will see the option Objective-C Automatic Reference Counting.
选择您的项目或目标,然后转到“构建设置”,在Apple LLVM 编译器 3.0 - 语言部分下,您将看到选项Objective-C 自动引用计数。
回答by Josh B
For towpse, in Xcode 4.6 you will need to look for "CLANG_ENABLE_OBJC_ARC" and then change it to "Yes" to enable.
对于拖车,在 Xcode 4.6 中,您需要查找“CLANG_ENABLE_OBJC_ARC”,然后将其更改为“是”以启用。