Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional compilation when using ARC

Is there a way to ask the compiler if ARC is turned on, and then conditionally compile based upon that value? For example, I have a protocol:

@protocol ProtocolA

@required
-(void)protocolMethodOne

@optional
-(void)protocolMethodTwo;

@end

If I'm using ARC, I would like to make protocolMethodA optional when using ARC, and required when not using ARC. This is because one of the main reasons for utilizing this method is to dealloc the object instance.

With that said, here's what I would like to happen:

@protocol ProtocolA

#ifdef SOME_ARC_VARIABLE
    @optional
#else
    @required
#endif
-(void)protocolMethodOne

@optional
-(void)protocolMethodTwo;

@end
like image 749
FreeAsInBeer Avatar asked Dec 09 '11 14:12

FreeAsInBeer


1 Answers

You should do #if __has_feature(objc_arc) That will expand to 1 in the case of ARC being enabled.

This is from the ARC docs from Clang.

like image 60
Joshua Weinberg Avatar answered Oct 07 '22 12:10

Joshua Weinberg