Subclass non-ARC file into ARC project in Xcode 4

痴心易碎 提交于 2019-12-04 13:47:47

问题


I am using some non-ARC code in my ARC project, namely Three20. I have added all the appropriate compiler flags and all works well. However, I need to subclass some of the Three20 classes, and I'm not sure if I should add the compiler flag to my new file for non-ARC, or if the compiler will figure it out, and add the appropriate release calls.

Just to recap: - ARC project in XCode 4 - Includes non-ARC code (Three20) - Need to subclass something defined in non-ARC files - Do I need to add release calls? - Do I need to add compiler flag for non-ARC in subclass?


回答1:


Michael,

ARC is a compile time technology that determines retain/release semantics based upon whether a given slot in memory will persist beyond the current method/function invocation. Because of this, you can safely intermix subclasses using ARC or not. I do it all of the time. I also do it in categories. Unlike garbage collection, ARC is quite focussed on just the storage space in each method/function. BTW, most of iOS's frameworks do not appear to yet use ARC. Hence, any subclass you make of a framework class has this "problem" and it just isn't an issue.

To answer your specific question:

Just to recap: - ARC project in XCode 4 - Includes non-ARC code (Three20) - Need to subclass something defined in non-ARC files - Do I need to add release calls? - Do I need to add compiler flag for non-ARC in subclass?

Your subclass of a non-ARC superclass can be either ARC or not. As the default setting for your app is ARC, you need do nothing to your subclass.

Andrew




回答2:


Yes, you need to add non-ARC flag (-fno-objc-arc) and retain / release calls.

Don't add it if your subclass does use ARC, but I recommend against this, because it would just be asking for trouble.



来源:https://stackoverflow.com/questions/8790620/subclass-non-arc-file-into-arc-project-in-xcode-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!