Created
July 25, 2015 06:34
-
-
Save toshi0383/7b45633de499caa857e9 to your computer and use it in GitHub Desktop.
Boolを返すメソッドならwhereに書けるってことみたい。 #cswift #CodePiece
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
| 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