-
Book Overview & Buying
-
Table Of Contents
Mastering Swift 6 - Seventh Edition
By :
Developing our applications for the latest Operating System (OS) version gives us access to all the latest features for the platform that we are developing for. However, there are times when we want to also target older platforms. Swift allows us to use the availability attribute to safely wrap code to run only when the correct version of the operating system is available.
The availability attribute is only available when we use Swift to develop for Apple platforms, and is not available for Linux or Windows development.
The availability attribute essentially lets us run a block of code, if we are running on the specified version of the operating system or higher; otherwise, run another block of code.
There are two ways in which we can use the availability attribute. We can use an if or a guard statement with the availability attribute to run a specific block of code, or we could use the availability attribute to mark a method or type...