如何在 Xcode 4.2 中启用 ARC 项目范围 [英] How do you enable ARC project-wide in Xcode 4.2

查看:18
本文介绍了如何在 Xcode 4.2 中启用 ARC 项目范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想要使用 ARC 转换的 iOS 应用.我只会使用迁移工具,但在预览阶段它总是会出错.

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.

我知道我可以逐个文件地使用 -fobjc-arc 编译器指令,但我想在整个项目上启用 ARC,然后使用 -fno-objc-arc 关闭个别类.

I know I can use the -fobjc-arc compiler directive on a file-by-file basis, but I want to enable ARC on the entire project, then turn off individual classes using -fno-objc-arc.

4.2的新项目默认可以使用ARC,所以一定有什么地方可以切换的.

New projects in 4.2 can use ARC by default, so there must be a switch somewhere.

谁能帮我把项目转换成ARC

推荐答案

"ARC 在 Xcode 4.2 中可用,目前处于测试阶段,并且仅在使用 Clang(又名Apple LLVM 编译器")进行编译.设置是显然,它被称为Objective-C 自动引用计数".打开它,然后关闭.

"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.

如果您正在处理现有代码,则更改此设置将产生大量的错误.ARC 不仅为您管理内存,但它禁止你尝试自己做.这是违法的使用 ARC 时手动发送保留/释放/自动释放.由于正常非 ARC 可可代码中到处都是这些东西,你会得到很多错误.

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.

幸运的是,Xcode 提供了一个转换现有代码的工具.选择编辑-> 重构... -> 转换为 Objective-C ARC... Xcode 将指导您完成代码转换.虽然可能有一些在需要帮助的情况下弄清楚该做什么,该过程应该在很大程度上是自动的."

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."

我从这个链接中得到它,对我帮助很大:http://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html

I took that from this link, helped me a lot: http://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html

这篇关于如何在 Xcode 4.2 中启用 ARC 项目范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆