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?
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
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