April 2017
Intermediate to advanced
316 pages
9h 33m
English
An expression pattern represents the value of an expression. Expression patterns appear only in a switch statement's case labels. The expression represented by the expression pattern is compared with the value of an input expression using the ~= operator.
The matching succeeds if the ~= operator returns true. By default, the ~= operator compares two values of the same type using the == operator. The following example presents an example of the expression pattern:
let position = (3, 5) switch position { case (0, 0): print("(0, 0) is at the origin.") case (-4...4, -6...6): print("(\(position.0), \(position.1)) is near the origin.") default: print("The position is:(\(position.0), \(position.1)).") }
We can overload ...
Read now
Unlock full access