Skip to content

Instantly share code, notes, and snippets.

@markcerqueira
Created November 13, 2016 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markcerqueira/c35914171658c2bb256c43fe5819c113 to your computer and use it in GitHub Desktop.
Save markcerqueira/c35914171658c2bb256c43fe5819c113 to your computer and use it in GitHub Desktop.
Trailing Closures in Swift
// Adapted from https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html
// Here's a function that takes a closure as an argument:
func funFunction(closure: () -> Void) {
// Do stuff and call closure when done
}
// Here's how you call this function passing the closure normally:
funFunction(closure: {
// Closure code goes in here
})
// Here's how you call this function with a trailing closure:
funFunction() {
// Closure is declared OUTSIDE the function's argument list!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment