Switch must be exhaustive, consider adding a default clause
截图
0赞 · 0采集
措言
2017-06-08
fallthrough
截图
0赞 · 0采集
措言
2017-06-08
case let str where str.hasSuffix("运算符"):
println("课程《\(courseName)》是介绍运算符的课程")
截图
0赞 · 0采集
措言
2017-06-08
let courseInfo = ("3-2", "区间运算符")
switch courseInfo
{
case (_, let courseName) where courseName.hasSuffix("运算符"):
println("课程《\(courseName)》是介绍运算符的课程")
}
截图
0赞 · 0采集
措言
2017-06-08
case let (x, y) were x == y:
截图
0赞 · 0采集
措言
2017-06-08
let coordinate = (3, 3)
switch coordinate
{
case (let x, 0):
println("the x value is \(x)")
}
截图
0赞 · 0采集
措言
2017-06-08
let coordinate = (1, 1)
switch coordinate
{
case (-2...2, -2...2):
println("\(coordinate.0), \(coordinate.1)")
}
截图
0赞 · 0采集
措言
2017-06-08
var coordinate = (1,1)
switch coordinate
{
case (1,1):
println("")
}
截图
0赞 · 0采集
措言
2017-06-08
switch score
{
cas 90..<100:
println("Perfect")
}
截图
0赞 · 0采集
布边的天空
2016-08-26
switch语句
截图
0赞 · 0采集
Genment
2016-05-02
视频中关于 fallthrough 的说法是错误的,右边的 Console Output 才是真相(default 都打印出来了)。
关于 fallthrough,当前swift2.2文档描述如下:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html
fallthrough 只能用于 switch-case 中,fallthrough 会使程序跳出当前 case,直接进入下一个 case,并不会判断是否满足下一个 case 的条件,且 fallthrough 后面的语句将不会被执行(类似于 continue/break/return)
fallthrough 可以出现在 switch 中的任意地方,而不仅仅是作为一个 case 语句块中的最后一个语句,但是,不能出现在最后一个 case 语句块中(因为后面已经没有 case 可以跳进去了)。
当下一个 case 块包含 value binding 时,也不能使用 fallthrough 跳到下一个 case 中去(因为不会进行判断,也就是说 case 的条件是不会执行的,而 value binding 是在 case 标签中定义变量/常量的,不会执行就会导致变量/常量未定义,所以会出错)。
截图
0赞 · 0采集
慕粉3238482
2016-04-26
fallthrough
0赞 · 0采集
大树先生丶
2016-03-30
自带break
可以用fallthough继续
0赞 · 0采集
慕仙3488553
2016-03-09
1.在swift语言中switch可以对相应的变量进行逻辑判断:
Let courseinfo = (3-2,"区间运算符")
switch courseinfo
{
case (_,Let coursename) where coursename.hasSuffix("运算符")://因为不关心courseinfo的键所以使用_,where 是做逻辑判断的关键字,判断coursename中后缀是否包含“运算符”,判断后缀是否包含用(hasSuffx)如果包含输出
println("课程《\(coursename)》是介绍运算符的课程")
default:
println("\(courseinfo.1)是其他课程")
}
如果想在switch进入一个case后还进入下一个case,可以在case后加fallthrough
0赞 · 0采集
慕仙3488553
2016-03-09
1.swift语言中switch判断不再局限于整型和字符型,字符串、布尔等类型也可以
0赞 · 0采集
qq_一生相守_0
2016-02-14
swift中switch判断不再局限于整型和字符型,字符串、布尔等类型也可以
截图
0赞 · 0采集
大浓妆掩饰小悲伤
2016-01-03
case Int..<Int
case (Int, Int)
case (Int, _)
case (Int...Int, Int...Int)
利用value binding提取switch的元组中的元素
case let (x, y) where x == y: (这实际上是因为swift的switch可以判断bool类型)
fallthrough 继续向下判断case语句
0赞 · 0采集
qq_巫师_0
2015-12-07
条件选择
截图
0赞 · 0采集
胡子向右
2015-12-06
switch case 必须包含所有情况,case 不包含所有情况时要有default , case 包含所有情况时可以省略 default