Illep
Illep

Reputation: 16859

Adding the tag to a ARC enabled project

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.

Upvotes: 1

Views: 900

Answers (2)

Nick Lockwood
Nick Lockwood

Reputation: 41005

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

#if __has_feature(objc_arc)
...
#endif

You could use this to raise a warning, by saying

#warning This file is not ARC compatible, add the -fno-objc-arc tag

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.

Upvotes: 6

dtuckernet
dtuckernet

Reputation: 7895

No - not in the code itself. This is stored in your project file, so if you send the entire project to someone else it should work. However, you can't just send them a few classes and have that work (it needs to be the entire project).

Upvotes: 1

Related Questions