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

  • 關於本站
  • 免責聲明