Last active
November 21, 2016 15:13
-
-
Save sketchytech/bf202a2e5676964a851aad541e074de4 to your computer and use it in GitHub Desktop.
Swift: regular closure vs auto closure
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
// a regular method that doesn't have any arguments | |
func regularClosure(str:() -> String) { | |
str() | |
} | |
regularClosure{"print me!"} | |
// can be replaced with an @autoclosure | |
func autoClosure(@autoclosure str:() -> String) { | |
str() | |
} | |
autoClosure("print me!") | |
// but one that takes an argument cannot | |
func regularClosureWithArgument(str:(String) -> String) { | |
str("print me!") | |
} | |
regularClosureWithArgument{$0} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment