Question

When compiling an older project in Xcode 4.5, there is a warning:

'__bridge' casts have no effect when not using ARC

What's the proper way to get rid of this warning, such that the code works well in both ARC and non-ARC projects?

Was it helpful?

Solution

Any individual source file has to either be compiled with ARC or not compiled with ARC. You should just make up your mind which it is and always use that method for the particular source file. Provided you stick to the memory management naming conventions, you can mix ARC and non ARC source files in the same project.

The reason I say the above, is that if you have code that was written for ARC and you compile it without ARC, there will be memory leaks and premature deallocations all over the place thanks to the fact that all of the retains, releases and autoreleases are missing.

OTHER TIPS

With a few #define's it is quite possible to write source files which compile correctly for more than one of MRC, ARC & GC.

Xcode does not allow you to enable both ARC & GC, knowing that we can write:

#if defined(__OBJC_GC__)
#  define USING_GC 1
#else
#  define USING_GC 0
#endif

#if __has_feature(objc_arc)
#  define USING_ARC 1
#else
#  define USING_ARC 0
#endif

#if USING_ARC || USING_GC
#  define USING_MRC 0
#else
#  define USING_MRC 1
#endif

which will define just one of USING_GC, USING_MRC and USING_ARC as 1 and the other two as 0. You can put that in your projects prefix header (.pch).

You can use these defines directly in your code to include/exclude things like bridge casts; or better to define macros for memory calls, casting, etc. which expand to the appropriate code based on the memory model in use.

HTH

Simply turn on ARC for that file:

-fobjc-arc

(Go to Build Phases > Compile Sources > Compiler Flags)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top