logo
  • 教程列表
  • SO官方文檔
  • 開關
    • 開關和選項
    • 基本用法
    • 匹配範圍
    • 在開關中使用 where 語句
    • 部分匹配
    • 匹配多個值
    • 使用開關滿足多個約束之一
    • 開關和列舉
    • 開關和元組
    • 基於類的匹配 - 非常適合 prepareForSegue
    • 切換漏洞
  1. StackOverflow 文件
  2. Swift Language 教程
  3. 開關
  4. 開關和列舉

開關和列舉

Created: November-22, 2018

Switch 語句與 Enum 值非常相似

enum CarModel {
    case Standard, Fast, VeryFast
}

let car = CarModel.Standard

switch car {
case .Standard: print("Standard")
case .Fast: print("Fast")
case .VeryFast: print("VeryFast")
}

由於我們為汽車的每個可能值提供了一個案例,我們省略了 default 案例。

  • 開關和元組
  • 使用開關滿足多個約束之一

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明