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

  • 关于我们
  • 免责声明