Swift 入門指南 V1.00 - 單元 9 範例




CH09.playground


enum Numbers {
    case One
    case Two
    case Three
    case Four
}

var choice = Numbers.Three
switch choice {
case .One:
    println("1")
case .Two:
    println("2")
case .Three:
    println("3")
case .Four:
    println("4")
}

enum Numbers2 {
    case Five(Int, Int, Int, Int)
    case Six(String)
}

let choice2 = Numbers2.Five(1, 2, 3, 4)
switch choice2 {
case .Five:
    println("5")
case .Six:
    println("6")
}

enum Numbers3: Int {
    case Seven = 1
    case Eight = 2
    case Nine = 3
    case Ten = 4
}

let decision = 2
if let choice3 = Numbers3(rawValue: decision) {
    switch choice3 {
    case .Seven:
        println("7")
    case .Eight:
        println("8")
    case .Nine:
        println("9")
    case .Ten:
        println("10")
    }
}

struct StructDemo {
    // task
}

class ClassDemo {
    // task
}

the end

沒有留言: