import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// demo(num: 10 )
demo(num: "8" )
}
// swith 可以针对任意类型的值进行分支,不再局限整数
// 如果用多值 用 ,隔开
func demo(num:String) {
switch num {
case "9","10":
print("优秀")
default:
print("一般")
}
}
func demo1( ) {
let point = CGPoint(x: 10, y: 10)
switch point {
case let p where p.x == 0 && p.y == 0 :
print("原点")
case let p where p.x == 0 :
print("Y轴")
case let p where p.y == 0 :
print("X轴")
case let p where abs(p.x) == abs(p.y) :
print("对角线")
default:
print("其他")
}
}
}
网友评论