The availability attribute
Using the latest SDK gives us access to all of 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 was first introduced in Swift 2.
The availability blocks essentially lets us say, "If we are running the specified version of the operating system or higher, run this code. Otherwise, run some other code." There are two ways in which we can use the availability attribute. The first way allows us to execute a specific block of code and can be used with an if or guard statement. The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access