April 2026
Intermediate
683 pages
25h 29m
English
Defensive programming is a vital part of any programming platform, and Swift is no exception to that. In this chapter, you will learn what Swift has to offer in terms of handling errors.
Errors are unpleasant but unavoidable. As programmers, we don’t have the luxury to write a chunk of code and assume that everything will function perfectly just as we’ve foreseen. This is a false hope, sure to be doomed. Table 12.1 contains some sample scenarios in which errors might occur.
|
Scenario |
Hope |
Reality |
|---|---|---|
|
Accessing a RESTful API |
The service will return values in the expected JSON format |
The API’s JSON format might be changed by an unannounced update |
|
Reading settings from a file |
The file is present; settings have ... |
Read now
Unlock full access