O'Reilly logo

Learn Swift 2 on the Mac, Second Edition by Waqar Malik

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter    6

Operators

General-purpose languages provide set of operators—convenience constructs that behave like functions—and Swift is no different. You’ve already seen at least one such operator: +. Swift provides a wide range of built-in operators and allows you to define operators for your own classes and to extend built-in classes to add new operators.

Syntax

Operators in Swift can be:

  • Unary, which requires only one operand or input. (-a).
  • Binary, which requires two operands or inputs. (a+b).
  • Ternary, which requires three operands. (?:).

Notation

Operators come in one of three notations:

  • Prefix, where the operator comes before the operand(s). The operator can be either unary or binary. (++a)
  • Infix, where the operator requires two operands ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required