switch语句中使用
let scores = [20,8,59,60,70,80]
scores.forEach {
switch $0{
case let x where x>=60:
print("及格")
default:
print("不及格")
}
}
scores.forEach { (x) in
print(x)
}
for语句中使用
let scores = [20,8,59,60,70,80]
for score in scores where score>=60 {
print("这个是及格的:\(score)")
}
do catch中使用
enum ExceptionError:Error{
case httpCode(Int)
}
func throwError() throws {
throw ExceptionError.httpCode(500)
}
do{
try throwError()
}catch ExceptionError.httpCode(let httpCode) where httpCode >= 500{
print("server error")
}catch {
print("other error")
}