31

I have an iOS refactoring library that I want to work with and without the ARC compilation option. Is there a way to detect during compilation, like with an #ifdef, if ARC is available?

1 Answer 1

50

Yes, you can use the following:

#if __has_feature(objc_arc)
  ...
#endif

Even if you're using the latest version of LLVM, this will only evaluate to true if you're compiling with the -fobjc-arc option.

2
  • 1
    It seems to be working! I'll just wrap my retain/release stuff in that. Oct 10, 2011 at 14:03
  • 3
    +1, also thanks to your answer I found __has_feature(objc_arc_weak)
    – orip
    Aug 23, 2012 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.