1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
import UIKit
enum CompassPoint { case North case South case East case West }
enum Something { case One, Two }
var directionToHead = CompassPoint.West
enum BarCode { case UPCA(Int, Int, Int, Int) case QRCode(String) }
var productBarcode = BarCode.UPCA(8, 21212, 3223, 3) productBarcode = BarCode.QRCode("AAAAAAAAA")
switch productBarcode { case .UPCA(let a, let b, let c, let d): print("\(a + b + c + d)") case .QRCode(let e): print(e) }
enum ASCIIControlCharacter: Character { case Tab = "\t" case LineFeed = "\n" case CarriageReturn = "\r" } print(ASCIIControlCharacter.Tab) print(ASCIIControlCharacter.Tab.rawValue)
enum Planet: Int { case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Nepture }
print(Planet.Earth) print(Planet.Earth.rawValue) let possiblePlanet = Planet(rawValue: 4) let possiblePlanet1 = Planet(rawValue: 9)
indirect enum AE { case Number(Int) case Addition(AE, AE) case Multiplicaiton(AE, AE) }
func evaluate(expression: AE) -> Int { switch expression { case .Number(let value): return value case .Addition(let left, let right): return evaluate(left) + evaluate(right) case .Multiplicaiton(let left, let right): return evaluate(left) * evaluate(right) } }
let exp = AE.Addition(AE.Number(5), AE.Multiplicaiton(AE.Number(4), AE.Number(7))) print(evaluate(exp))
|