Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mixing Automatic Refrencing Count vs Manual Refrence Counting...

45 views
Skip to first unread message

SpreadTooThin

unread,
Nov 24, 2012, 12:54:10 AM11/24/12
to
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?

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?

// These statements won't work in ARC mode.

conn = [socket retain];
[host release];
[conn autorelease];
[super dealloc];

Any simple rule to follow to fix these lines of code?

Greg Parker

unread,
Nov 27, 2012, 8:31:23 PM11/27/12
to
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

0 new messages