_Nonnull keyword use in older Xcode

We have to run code that was written in Xcode 7.x and uses _Nonnull keyword, in Xcode 6.2 on Mavericks. Is there a way to organize code such that I can still leave the keywords in when it is compiled in Xcode 7 but not when it is Xcode 6.

Replies

Well, the traditional way to do this is to use a conditional macro to "define away" the symbol:


#if <this is Xcode 6>

#define _Nonnull

#endif


One thing to keep in mind that nullability specifiers did exist in Xcode 6 (at least by 6.3, I didn't look back any further than that), but the symbol was then "__nonnull". However, the ground is treacherous, because the usage rules may have changed slightly since then, apart from the name itself, and because Xcode 7+ may play its own macro definition games to keep the old Xcode 6 symbols around for compatibility.


So you may have to do some playing around, and browsing of SDK header files, to find out what's safe to do.

You might want to duplicate the target and use one for each IDE, rather than building a tangled web 😉