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

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

问题描述

我想要使用 ARC 转换为iOS应用。我只会使用迁移工具,但在预览阶段我会一直出错。



我知道我可以使用 -fobjc- arc 逐个文件的编译器指令,但我想在整个项目中启用 ARC ,然后使用关闭各个类 - FNO-objc弧



4.2中的新项目默认情况下可以使用ARC,因此必须在某处设置开关。



任何人都可以帮我将项目转换为 ARC


解决方案

ARC可在Xcode 4.2,目前处于测试阶段,只有当
与锵(又名编译 苹果LLVM编译器),设定为$叫,显然不够b $ b, Objective-C的自动引用计数。
打开它,然后关闭。



如果您正在处理现有代码,更改此设置将产生
出错信息的一个巨大的数量。ARC不仅管理内存给你,
,但它禁止你想自己做。这是违法的
手动发送使用ARC时保留/释放/自动释放。由于正常
非ARC Cocoa代码充斥着这些东西,你会得到很多
的错误。



幸运的是,Xcode提供了一个工具来转换现有代码。 选择编辑
- >重构... - >转换为Objective-C ARC
...并且Xcode将指导您转换代码。虽然可能有一些
的情况需要帮助找出要做的事情,但是b b $ b的过程应该基本上是自动的。


我从这个链接中获取了这个,帮了我很多:
http://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html


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.

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.

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

Can anyone help me to convert the project to ARC

解决方案

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

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天全站免登陆