Created
October 10, 2015 09:03
-
-
Save dolphinsue319/df2087cda23ba2d9ff5f to your computer and use it in GitHub Desktop.
~= 的簡單範例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment