Using Swift Types
In This Chapter
Exploring Swift types
Refining type declarations and references
Using types to improve readability of code
Working with tuples and optionals
In most programming languages, variables and constants not only have values, they also have types. C (the progenitor of many of today’s languages) provided four basic arithmetic types (
double) that can then be enhanced with optional specifiers, such as
long to form more complex and sophisticated types.
Adding types for variables and constants means that the compiler at runtime can perform more efficiently and can more easily check for errors. For example, in most languages, assigning “Hello” to an
int type is a mistake likely to raise an error or exception at compile- or run-time. In a properly written app, every error or exception raised is a crash that’s been averted (provided that you’ve done your part by adding the necessary error- and exception-checking code to catch those errors).
Together with assertions (which are discussed at the end of ...