Search code examples
xcode4osx-lionosx-snow-leopard

Which Xcode macros can be used to check the OS version of the compiling computer?


Building an iOS application using Xcode 4: 2 developers, one with 10.6.8 and one with 10.7. In 10.7 the NSURLConnectionDelegate interface is explicit: it is defined and can be added to the interface declaration. In 10.6.8 however, it isn't defined and a compile error is generated (NSURLConnectionDelegate: cannot find protocol declaration). This error can be fixed by simply removing the declaration. I'm looking for a compiler macro that identifies which OS version the code is being built on so I can modify the code to be compatible with both OS versions. Something like:

#if _CURRENT_OS_X_IS_10_7_OR_HIGHER
@interface appDelegate : NSObject<UIApplicationDelegate, NSURLConnectionDelegate> {
#else
@interface appDelegate : NSObject<UIApplicationDelegate> {
#endif

Solution

  • You should be able to use NSAppKitVersionNumber and/or NSFoundationVersionNumber17_0

    EDIT

    As you compile for iOS, you won't be able to use any macro coming from a Mac OS framework. Your only chance is the Xcode/GCC predefined macros.

    You can check them with:

    gcc -arch i386 -dM -E - < /dev/null | sort
    

    This seems interesting:

    __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__