Chapter    17

Expressions

Expressions are the building blocks of any program. Values, variables, constants, and functions are combined to form expressions, which, in turn, are combined to form a program. When the program is run, expressions are interpreted according to the rules set by the particular language. These rules can include precedence and associativity, and they produce results and possibly a new state for the program.

Swift is no different. It provides four types of expressions:

  • Primary
  • Prefix
  • Binary
  • Postfix

Evaluating expressions in Swift produces a result, a side effect, or both. There are some expressions that require more information. I’ll take a look at these and expand on their features and requirements.

Note  An expression ...

Get Learn Swift on the Mac: For OS X and iOS now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.