Skip to content

Instantly share code, notes, and snippets.

@dolphinsue319
Created October 10, 2015 09:03
Show Gist options
  • Save dolphinsue319/df2087cda23ba2d9ff5f to your computer and use it in GitHub Desktop.
Save dolphinsue319/df2087cda23ba2d9ff5f to your computer and use it in GitHub Desktop.
~= 的簡單範例
//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