Created
July 6, 2014 18:34
-
-
Save andybest/d3019ff1742012dbcf42 to your computer and use it in GitHub Desktop.
Adding Ruby-like times method to Swift integers
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
| extension Int { | |
| func times(it: () -> ()) { | |
| for i in 0..self { | |
| it() | |
| } | |
| } | |
| } | |
| // Use like so: | |
| 10.times { | |
| println("Hello, World!") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment