SpreadTooThin <
bjobr...@gmail.com> writes:
> I have an older Objective-C module that was developed before automatic reference counting in XCode.
>
> I also have new code that uses automatic reference counting.
>
> I know I can set Objective-C Automatic Reference Counting to Yes or No in the Target Setting.
>
> However I am mixing the two Reference Counting modes.
>
> Is there a #IFDEF I can put in the older module such that it compiles with automatic refrence counting off?
You can usually mix and match ARC and non-ARC code on a per-file
basis. ARC automatically enforces Cocoa's naming conventions, so as long
as all of the code follows Cocoa's naming conventions then the ARC code
and the non-ARC code will agree on retain count management.
You can enable ARC for your project and disable it for individual
files. In Xcode, choose your target, go to Build Phases > Compile
Sources, and add -fobjc-no-arc to Compiler Flags for your non-ARC files.
> Or is it time to bite the bullet and bring the old code up to data?
> Maybe there is a simple rule upgrading a class to automatic reference
> counting... like replace all retain with strong?
Xcode's ARC Migrator can help. Edit > Refactor > Convert to Objective-C
ARC. However, if you have an existing module that is mostly
self-contained then it may be easier to use it as-is now and convert to
ARC later.
--
Greg Parker
gpa...@apple.com Runtime Wrangler