Home > Back-end >  Support if-else ios 15 or lower than ios 15
Support if-else ios 15 or lower than ios 15

Time:08-26

I have specific line of code which only execute if ios version is lower than 15.

I could if-else if ios is great 15 by these.

            if #available(iOS 15.0, *) {
            }else {}

I would to do opposite of it. If ios version is lower than 15 then execute specfic line of code. I know I can write code in else part and it should have work but looking for more ideas and faster way for app

CodePudding user response:

For older versions of Swift, that's exactly how you do it.

Swift 5.6 (i.e. Xcode 13.3 or newer) added the condition you're asking for, as #unavailable, so you can now do this:

if #unavailable(iOS 15.0) {
    // only runs if <iOS 15
}

All the details are here: https://github.com/apple/swift-evolution/blob/main/proposals/0290-negative-availability.md

  • Related