What's the Swift equivalent of Objective-C's “#ifdef __IPHONE_11_0”?

后端 未结 5 1970
旧时难觅i
旧时难觅i 2021-02-05 06:50

I want to use Xcode 9 to add iOS 11 code to my project while keeping the option to compile the project with Xcode 8 which only supports iOS 10.

In Objective-C I can do t

5条回答
  •  半阙折子戏
    2021-02-05 07:49

    The iOS 11 SDK comes with Swift 3.2 (or Swift 4), so you can use a Swift version check to accomplish the same thing:

    #if swift(>=3.2)
        if #available(iOS 11.0, *) {
            …
        }
    #endif
    

提交回复
热议问题