Last active
March 20, 2017 21:47
-
-
Save kkirsche/2d368ee1f0a87666e16c to your computer and use it in GitHub Desktop.
Swift Closure Shorthand Syntax
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
| // Closure Shorthand Syntax | |
| // Rule #1: Full closure syntax | |
| [1,2,3,4,5].map({ (i: Int) -> Int in return i * 3 }) | |
| // Rule #2: Inferring types from context | |
| [1,2,3,4,5].map({ i in return i * 3 }) | |
| // Rule #3: Implicit Returns from Single Expression Closures | |
| [1,2,3,4,5].map({i in i * 3}) | |
| // Rule #4: Shorthand Argument Names | |
| [1,2,3,4,5].map({ $0 * 3 }) | |
| // Rule #5: Trailing Closures | |
| [1,2,3,4,5].map() { $0 * 3 } | |
| // Rule #6: Ignoring Parentheses | |
| [1,2,3,4,5].map { $0 * 3 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment