Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Created July 25, 2015 06:34
Show Gist options
  • Select an option

  • Save toshi0383/7b45633de499caa857e9 to your computer and use it in GitHub Desktop.

Select an option

Save toshi0383/7b45633de499caa857e9 to your computer and use it in GitHub Desktop.
Boolを返すメソッドならwhereに書けるってことみたい。 #cswift #CodePiece
let op:[Int?] = [1,2,3,nil,5]
func a() { print("brown") }
func a(value:Int) -> Bool { print("yellow"); return true }
func a() -> Bool {print("green");return true}
for case let v? in op where a(v) { print(v) }
for case let v? in op where a() { print(v) }
// yellow
// 1
// yellow
// 2
// yellow
// 3
// yellow
// 5
// green
// 1
// green
// 2
// green
// 3
// green
// 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment