Xcode 5, availability macros, and flagging weak-linked or unavailable symbols from a newer SDK

If you find yourself using a newer SDK to build an iOS or MacOS app for an older OS version, Xcode allows you to set the deployment target to the lower OS version. It will automatically weak-link the symbols, so they are imported at run-time. That means you need to carefully check your code to see where you are using these newer symbols. In those places, make sure you test to see if the symbol (method, enum, class, constant) is available before using it.

The compiler can find these weakly imported symbols for you. In Xcode 5, the magic macros to automatically check where you are using from the SDK that are not available in your deployment target OS are below. Here, they will flag the symbols that were introduced in 6.0 and newer. Useful if you’re still targeting iOS 5. Adapt to your situation (SDK/deployment target) and add to your precompiled headers to run the checks.

#undef __NSi_6_0
#define __NSi_6_0 deprecated=1.0
#undef __NSi_6_1
#define __NSi_6_1 deprecated=1.0
#undef __NSi_7_0
#define __NSi_7_0 deprecated=1.0

#undef __NSd_6_0
#define __NSd_6_0
#undef __NSd_6_1
#define __NSd_6_1
#undef __NSd_7_0
#define __NSd_7_0

Leave a comment

Your comment