enum compassPoint { case East case West case South case North }
var directionToHead = compassPoint.East
switch directionToHead { case .East: println("East") case .West: println("West") case .South: println("South") case .North: println("North") default: println("No value") }
Associated Value
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
enum Barcode { case UPCA(Int, Int, Int) case QRCode(String) }
var productBarcode = Barcode.UPCA(1, 123_456_789, 222) productBarcode = .QRCode("ABCDEFGHIJKLMNOP")
switch productBarcode { case .UPCA(let numberSystem, let identifier, let check): println("UPC-A with value of \(numberSystem), \(identifier), \(check).") case .QRCode(let productCode): println("QR code with value of \(productCode).") }