Created
July 17, 2014 19:08
-
-
Save soffes/f140254c41b633e38e69 to your computer and use it in GitHub Desktop.
Each on Array in Swift
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 Array { | |
func each(block: ((Element) -> Void)) { | |
for i in 0..<count { | |
block(self[i]) | |
} | |
} | |
func eachWithIndex(block: ((Element, Int) -> Void)) { | |
for i in 0..<count { | |
block(self[i], i) | |
} | |
} | |
} |
Oh, that is nicer. Good call.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also do