-
Book Overview & Buying
-
Table Of Contents
Mastering Swift 6 - Seventh Edition
By :
Where the availability attribute lets us run a block of code, if we are running on the specified version of the operating system or higher, the unavailability attribute lets us run a block of code if we are not running on the specified version of the operating system or higher.
Prior to the unavailability attribute we may have had code similar to this:
if #available(iOS 16, *) { } else {
// Functionality to make iOS 15 and earlier work
}
This would be used when we needed code to make the functionality of our application work when it is being run on an older version of the operating system. Now with the unavailability attribute we can write the code like this:
if #unavailable(iOS 16) {
// Functionality to make iOS 15 and earlier work
}
An important difference between the availability and unavailability attributes is that the platform wildcard * is not allowed with the unavailability attribute. This is to avoid issues about which platforms should be considered...