December 2018
Intermediate to advanced
414 pages
10h 19m
English
Ranges come in two flavors: Range and ClosedRange. The difference between Range and ClosedRange is the inclusion of the upper bound. In a ClosedRange, the upper bound is included; in Range, it isn't.
If you want to include all numbers between 0 and 10, not including 10, you can represent it in two ways, as follows:
let range1 = 0..<10let range2 = 0...9range1.contains(10) // false
The two ranges are equivalent, and they contain the same numbers. They read differently and carry different meanings, however depending on what you want to express, you may want to pick one over the other. Ranges work with the Comparable protocol, which means that any type that conforms to this Comparable protocol is suited for creating ranges. ...
Read now
Unlock full access