I'd like to use a C++ library in my Objective-C app and to do so, I have an intermediate static library that will use Objective-C++ (.mm files instead of .m). The static library will, in turn, be used by my iOS app.
In the Objective-C++ library, is it safe to enable ARC or should I let my Objective-C app handle that?
TL;DR answer: choose whichever one you like, but preferably support both. If you want ARC, use it. If you don't want ARC, don't use it. (Deducing from your question, you may very well be a beginner - in this case I advise you to learn manual memory management well just so that you know and understand what and why is going on with reference counting, then you can transition to using ARC in production code later.)
If you distribute the binary static library file itself (MyLibrary.a
), then it doesn't make any difference. As @nil has already pointed it out: ARC is a compile-time technology (explaining in an overly simplified manner, it just inserts calls to retain
, release
and autorelease
. It has no effect on link time, let alone on runtime). So once the code is compiled, no one can tell if you used ARC, thus the user of your library won't need to worry about that either.
If you, however, distribute the source code of your library (which I strongly encourage), then the user needs to know whether or not you designed it to be used under ARC or without it. So decide once and then be consistent - you may prefer ARC code for ease of use and writing or non-ARC code for backwards compatibility. The ideal attitude would be to support both ARC and non-ARC compilation, using compile-time feature detection with the special macro __has_feature(objc_arc)
.