Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //pattern 是 case 後接的參數,value 是 switch 後面接的參數
- func ~=(pattern: String, value: Int) -> Bool {
- return pattern == "\(value)"
- }
- //這個會被代入 ~= 函數裡的 value
- let x = 1
- switch x {
- //這個會被代入 ~= 函數裡的 pattern
- case "1":
- print("GG")
- default:
- print("nothing")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement