简体   繁体   English

支持 if-else ios 15 或低于 ios 15

[英]Support if-else ios 15 or lower than ios 15

I have specific line of code which only execute if ios version is lower than 15.我有特定的代码行,只有在 ios 版本低于 15 时才会执行。

I could if-else if ios is great 15 by these.如果 ios 是伟大的 15,我可以。

            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.如果 ios 版本低于 15,则执行特定的代码行。 I know I can write code in else part and it should have work but looking for more ideas and faster way for app我知道我可以在其他部分编写代码,它应该可以工作,但正在寻找更多的想法和更快的应用程序方式

For older versions of Swift, that's exactly how you do it.对于旧版本的 Swift,您就是这样做的。

Swift 5.6 (ie Xcode 13.3 or newer) added the condition you're asking for, as #unavailable , so you can now do this: Swift 5.6(即 Xcode 13.3 或更高版本)将您要求的条件添加为#unavailable ,因此您现在可以这样做:

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所有细节都在这里: https://github.com/apple/swift-evolution/blob/main/proposals/0290-negative-availability.md

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM