• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why do we use -fobjc-arc instead of removing code with #define?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Why do we use -fobjc-arc instead of removing code with #define?
      • From: Uli Kusterer <email@hidden>
    • Re: Why do we use -fobjc-arc instead of removing code with #define?
      • From: Jerry Krinock <email@hidden>
References: 
 >Why do we use -fobjc-arc instead of removing code with #define? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Why do we use -fobjc-arc instead of removing code with #define?
  • Next by Date: Re: Why do we use -fobjc-arc instead of removing code with #define?
  • Previous by thread: Why do we use -fobjc-arc instead of removing code with #define?
  • Next by thread: Re: Why do we use -fobjc-arc instead of removing code with #define?
  • Index(es):
    • Date
    • Thread