In a ARC enabled project, is there a way to add the -fno-objc-arc tag programatically in the code it self.
So i could give my source files to someone else, and that person need not add the -fno-objc-arc manually.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume this is because you want to distribute your project as a re-usable library that can be used in other projects regardless of whether they use ARC?
I don’t think you can add the flag to the source to tell ARC to ignore the file (at least I’ve not found a way yet), but you can detect if ARC is enabled within the file using
You could use this to raise a warning, by saying
But an even more elegant solution is to use this feature to automatically branch your code at compile time so that it works on both ARC and non-ARC builds.
I wrote a simple re-usable header that can be pasted into the top of your source file or included in the project as a standalone header file:
https://gist.github.com/1563325
This provides a bunch of macros to use instead of retain, release and autorelease methods so that they can be automatically stripped for ARC builds. For an example of how this is used, check out iRate:
https://github.com/nicklockwood/iRate/tree/master/iRate
It only takes a few minutes to convert a class file this way.