Tip: Ensuring ARC is Enabled at Compile Time.

If you still have legacy code around that is not compiled with Automatic Reference Counting (ARC), accidentally adding some new code that assumes that ARC is enabled can lead to extensive memory leaks.

This simple test, placed in a .m file, will prevent the file from compiling if ARC is not enabled.

#if  ! __has_feature(objc_arc)
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

About idz

A professional software engineer dabbling in iOS app development.
This entry was posted in Code, Code Snippets, Objective-C, Tips and tagged , , . Bookmark the permalink.

Leave a Reply