iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
👇
[Swift] Using #unavailable to target OS versions below a specific version
Swift 5.6 introduces the #unavailable syntax in addition to the existing if #available.
By writing it as follows, you can execute code only on versions lower than iOS 15 (iOS 14 or below).
if #unavailable(iOS 15) {
// process
}
// Previously written like this
if #available(iOS 15, *) {} else {
// process
}
One thing to note is that #unavailable(iOS 15, *) results in an error. You might be tempted to include the * out of habit from writing #available(iOS 15, *), but the syntax is different here.
In the original proposal, it was suggested as #unavailable(iOS 15, *), but it seems it was changed during the second review.
Writing #unavailable(iOS 15) can be read as "the iOS version is not 15" (meaning it could be either 14 or 16), so I'm not a huge fan of it, but it is certainly true that it looks cleaner without the *.
Discussion