gpt4 book ai didi

ios - 如何在 Xcode 4.2 中启用 ARC 项目范围

转载 作者:IT王子 更新时间:2023-10-29 07:36:39 28 4
gpt4 key购买 nike

我有一个 iOS 应用程序,我想将其转换为使用 ARC。我只想使用迁移工具,但在预览阶段它总是给我出错。

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

4.2的新项目可以默认使用ARC,所以一定要有个开关。

谁能帮我把项目转换成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."

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

关于ios - 如何在 Xcode 4.2 中启用 ARC 项目范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7476692/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com