網頁

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

沒有留言:

張貼留言

0.留言請選擇註冊帳號, Google 或 OpenID 均可
1.歡迎留言交流,但不歡迎垃圾留言及廣告留言
2.文章相關問題歡迎提出,請減少情緒性留言
3.非文章相關內容,請到 G+ 社群 FB 社團提出
4.問作業之留言會被直接刪除
5.莫忘網路禮節
6.可使用部份HTML標記,如 <b> 、 <i> 、 <a>
7.站長保留刪除留言的權力