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

后端 未结 5 1829
旧时难觅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:44

    You can achieve, by doing this for function like below

    @available(iOS 11.0, *)
    func myFunction() {
     // function defination 
    }
    

    Or if you want check inside function write this

    if #available(iOS 11.0, *) {
        // iOS 11 specific stuff here
    } else if #available(iOS 10.0, *) {
       // iOS 10 specific stuff here
    } else {
        // non iOS 11 & 10 stuff here
    }
    

提交回复
热议问题