Enumerations
Syntax enum Direction { case up case down case left case right } Multiple case can appear on a single line, separated by commas: enum { case up, down, left, right } Use the Enumeration var dir = Direction.up When we want to modify the var after the initialized, we can use a shorter form of the enumeration. var dir = Direction.up dir = .down // The value's type has been inferred when the value is in initializing. Matching Enumeration Values with a Switch Statement enum Direction { case up case down case left case right } var dir = Direction.right switch dir { case .up: print("Go up") case .down: print("Go down") case .left: print("Go left") case .right: print("Go right") } Iterating over Enumeration Cases Conform to the CaseIterable protocol, to make the enumeration’s case be iterable. ...