Conditionally Hide Code from the Compiler

前端 未结 1 879
走了就别回头了
走了就别回头了 2020-12-05 16:40

So here\'s the problem. I\'m set to release an update soon for iOS that will address some problems in iOS 7. In order to do this, I need to use some specific iOS 7 functio

相关标签:
1条回答
  • 2020-12-05 17:10

    If you want to compile your app with two difference versions of Xcode or two different Base SDK settings then you should use compiler directives:

    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 // iOS 7.0 supported
        // iOS 7 code here
    #else
        // Pre-iOS 7 code here
    #endif
    

    Do not use this for runtime checks. This solution is only to be used when you must compile your code with two different versions. An example would be you have added iOS 7 code but you still need to compile the code with Xcode 4.6. Using the compile directives allows you to "hide" the iOS 7 code from the compiler using the older Base SDK.

    See the "SDK Compatibility Guide" in the docs for more on this and proper runtime checks.

    0 讨论(0)
提交回复
热议问题