禁用某些文件的自动引用计数 [英] Disable Automatic Reference Counting for Some Files
问题描述
我已经下载了iOS 5 SDK,发现ARC是新Apple编译器的一个很棒的功能。目前,许多第三方框架不支持ARC。我可以将ARC用于我的新代码并保持当前的保留/释放代码不变吗? ARC转换器在这里不起作用,因为某些框架(例如JSONKit)无法使用转换器转换为ARC。
I have downloaded the iOS 5 SDK and found that ARC is a great feature of the new Apple compiler. For the time being, many third party frameworks don't support ARC. Could I use ARC for my new code and keep the current retain/release code unchanged? The ARC converter doesn't work here, because some frameworks, such as JSONKit, cannot be converted to ARC by using the converter.
编辑:
答案是将 -fno-objc-arc
添加到您不希望ARC的文件的编译器标志中。在Xcode 4中,您可以在目标 - >构建阶段 - >编译源下执行此操作。
The answer is to add -fno-objc-arc
to the compiler flags for the files you don't want ARC. In Xcode 4, you can do this under your target -> Build Phases -> Compile Sources.
推荐答案
公共ARC文档,虽然在这一点上没有直接明确,但似乎暗示只要每个类都是所有ARC或全部手动管理,这些类可以集成到一个程序中。
The public ARC docs, while not directly clear on this point, seem to suggest that as long as each class is either all ARC or all manually-managed, the classes can be integrated into a single program.
您只能在一个类中混合ARC和非ARC;文件说发送保留
,发布
, autorelease
,在ARC代码中禁止使用 retainCount
消息(包括计时器和延迟执行,使用 @selector
)。因此,您不能在ARC类中执行非ARC(因为必要的消息被禁止),并且您不能在非ARC类中执行ARC(因为ARC添加的语法元素在没有ARC的情况下无效)。
You only can't mix ARC and non-ARC in a single class; the document says that sending retain
, release
, autorelease
, or retainCount
messages by any means (including timers and delayed performs, which use @selector
) is banned in ARC code. So you can't do non-ARC in an ARC class (because the necessary messages are banned) and you can't do ARC in a non-ARC class (because ARC adds syntax elements that are invalid without ARC).
对于是否可以将非ARC库/框架集成到ARC程序中,相同的文档更清楚:是的。它没有提到你是否可以在所有代码都是非ARC的程序中使用ARC库/框架,但鉴于上述所有内容,暗示似乎是肯定的。
The same document is a bit clearer on whether you can integrate non-ARC libraries/frameworks into an ARC program: Yes. It doesn't mention whether you can use ARC libraries/frameworks in a program where all your code is non-ARC, but given all of the above, the implication seems to be yes.
这篇关于禁用某些文件的自动引用计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!