I have seen some libraries use separate branches in their source control. One for ARC one for non-ARC. I dont see this as partical as it requires extra maintaince.
A method I thought was to use the compiler flag: (see this question)
#if __has_feature(objc_arc)
Whenever I need to use retain release etc… That way if the user has it switched on the code will automatically re-factor itself.
-
Is there a disadvantage of doing this way?
-
Is there a better way to do it?
While Dave’s answer is correct, there is an alternative pattern that avoids having to maintain two memory models in your code.
Namely, compile your code with ARC required and either:
use a static library to distrubute your code; whether that static library is built by a new target in the destination project or you distribute the library itself, ARC can be turned on for the target that builds the library.
turn on ARC for just the files when added to whatever target in the target project. ARC can be turned on per-file.
In any case, mixing ARC and non-ARC code at the per-file level is fully supported and works just fine (as demonstrated by the fact that the system frameworks are almost entirely compiled non-ARC, but work fine from ARC).