Chapter    5

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 executed, 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. We will take a look at these and expand on their features and requirements.

Note  An expression ...

Get Learn Swift 2 on the Mac, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.