Skip to content

Instantly share code, notes, and snippets.

@kkirsche
Last active March 20, 2017 21:47
Show Gist options
  • Select an option

  • Save kkirsche/2d368ee1f0a87666e16c to your computer and use it in GitHub Desktop.

Select an option

Save kkirsche/2d368ee1f0a87666e16c to your computer and use it in GitHub Desktop.
Swift Closure Shorthand Syntax
// 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