April 2017
Intermediate to advanced
316 pages
9h 33m
English
The wildcard pattern matches and ignores any value. It consists of an underscore, _. We use a wildcard pattern when we do not care about the values being matched against.
For instance, the following code example ignores the matched values:
for _ in 1...5 { print("The value in range is ignored") }
We use _ to ignore the value in the iteration.
The wildcard pattern can be used with optionals as follows:
let anOptionalString: String? = nil switch anOptionalString { case _?: print ("Some") case nil: print ("None") }
As seen from the preceding example, we matched an optional by _?.
The wildcard pattern can be used to ignore data that we do not need and values that we do not want to match against. The following code example ...
Read now
Unlock full access