Re: Why do we use -fobjc-arc instead of removing code with #define?
Re: Why do we use -fobjc-arc instead of removing code with #define?
- Subject: Re: Why do we use -fobjc-arc instead of removing code with #define?
- From: Dave DeLong <email@hidden>
- Date: Sat, 23 Jun 2012 18:41:31 -0700
Yep, you can do this. The #if you're looking for is:
#if __has_feature(objc_arc)
...
#endif
You can just scatter that everywhere in code, or you could do something like this:
#if __has_feature(objc_arc)
#define DD_RETAIN(_o) (_o)
#define DD_RELEASE(_o)
#define DD_AUTORELEASE(_o) (_o)
#else
#define DD_RETAIN(_o) [(_o) retain]
#define DD_RELEASE(_o) [(_o) release]
#define DD_AUTORELEASE(_o) [(_o) autorelease]
#endif
This way you can just do this, and not have to worry about whether ARC is on or not:
foo = DD_RETAIN(bar);
Cheers,
Dave
On Jun 23, 2012, at 6:37 PM, Jerry Krinock wrote:
> I'm curious as to why, when using non-ARC code, the recommendation is to "opt out" the file with -fobjc-arc.
>
> How about doing something like this…
>
> #ifndef HEY_ARC_IS_IN_USE
> [foo retain] ;
> #endif
>
> This way the file is fixed "once and for all", and I don't have to be setting -fobjc-arc every time I reuse this file from now until kingdom come. Certainly -fobjc-arc is also useful, but the #define seems to make much more sense for, say, my personal reusable class and class extension files which tend to be quite short. They contain only a few -retain, -release, etc.
>
> Does Apple even provide the required HEY_ARC_IS_IN_USE definition? I can't find any such thing.
>
> Jerry Krinock
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden