Created
November 13, 2016 07:50
-
-
Save markcerqueira/c35914171658c2bb256c43fe5819c113 to your computer and use it in GitHub Desktop.
Trailing Closures in Swift
This file contains 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
// 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