小编Ram*_*Ram的帖子

没有默认语句的Swift 3.0-Switch语句获取错误'切换必须是详尽的,考虑添加默认子句'

以下是用于在playground中执行Switch语句的代码.我执行了几个switch语句而没有使用default.我怀疑的是为什么它对某些人来说是可选的而且对于其他陈述是强制性的.谢谢提前!

let someNumber = 3.5

switch someNumber {

case 2 , 3 , 5 , 7 , 11 , 13 :
  print("Prime numbers")
case 4 , 6 , 24 , 12 , 66 :
  print("Normal numbers")

 }
Run Code Online (Sandbox Code Playgroud)

计数器语句在不使用默认值的情

  let yetAnotherPoint = (3,1)

  switch yetAnotherPoint {

  case let (x,y) where x == y :
   print("(\(x),\(y)) is on the line x == y")
  case let (x,y) where x == -y :
   print("(\(x),\(y)) is on the line x == -y")
  case let (x,y): …
Run Code Online (Sandbox Code Playgroud)

switch-statement swift3

-1
推荐指数
1
解决办法
6554
查看次数

标签 统计

swift3 ×1

switch-statement ×1