logo
  • 教程列表
  • SO官方文档
  • 开关
    • 开关和选项
    • 基本用法
    • 匹配范围
    • 在开关中使用 where 语句
    • 部分匹配
    • 匹配多个值
    • 使用开关满足多个约束之一
    • 开关和枚举
    • 开关和元组
    • 基于类的匹配 - 非常适合 prepareForSegue
    • 切换漏洞
  1. StackOverflow 文档
  2. Swift Language 教程
  3. 开关
  4. 匹配范围

匹配范围

Created: November-22, 2018

switch 语句中的单个 case 可以匹配一系列值。

let number = 20
switch number {
case 0:
    print("Zero")
case 1..<10:
    print("Between One and Ten")
case 10..<20:
    print("Between Ten and Twenty")
case 20..<30:
    print("Between Twenty and Thirty")
default:
    print("Greater than Thirty or less than Zero")
}
  • 在开关中使用 where 语句
  • 基本用法

Copyright © 2018. All right reserved

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

  • 关于我们
  • 免责声明