April 2017
Intermediate to advanced
316 pages
9h 33m
English
Algebraic data types can be composite types with variants as well. We could create an enum named Dimension to hold the length and width. We can express this enum in both us feet and metric meters. In Swift, we can define such an enum as follows:
enum Dimension { case us(Double, Double) case metric(Double, Double) }
Then we can use the Dimension enumeration to create a variable as follows:
let sizeMetric = Dimension.metric(5.0, 4.0)
Read now
Unlock full access