Conditional Compilation Using ARC

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

@protocol ProtocolA @required -(void)protocolMethodOne @optional -(void)protocolMethodTwo; @end 

If I use ARC, I would like to make protocolMethodA optional when using ARC and require when you are not using ARC. This is because one of the main reasons for using this method is to delete an instance object.

Having said that, here is what I would like to do:

 @protocol ProtocolA #ifdef SOME_ARC_VARIABLE @optional #else @required #endif -(void)protocolMethodOne @optional -(void)protocolMethodTwo; @end 
+7
objective-c iphone automatic-ref-counting conditional-compilation
source share
1 answer

You must do #if __has_feature(objc_arc) This will expand to 1 if ARC is enabled.

This is from Clang's ARC docs .

+14
source share

All Articles