Skip to content

Instantly share code, notes, and snippets.

@LucianoPAlmeida
Last active July 29, 2018 00:25
Show Gist options
  • Save LucianoPAlmeida/fcb12e91dcf166304567ef5d46501b3c to your computer and use it in GitHub Desktop.
Save LucianoPAlmeida/fcb12e91dcf166304567ef5d46501b3c to your computer and use it in GitHub Desktop.
// Awesome auto closures
class AwesomeType: CustomStringConvertible {
init() {
print("Initialize")
}
var description: String {
return "Description of an awesome type"
}
}
func awesomeAutoclosure(_ value: @autoclosure ()-> Any) {
print("Before")
print(value())
print("After")
}
func notSoAwesomeNonAutoclosure(_ value: Any) {
print("Before")
print(value)
print("After")
}
print("Awesome autoclosure")
awesomeAutoclosure(AwesomeType())
// Awesome autoclosure
// Before
// Initialize
// Description of an awesome type
// After
print("\n")
print("Not so awesome no autoclosure")
notSoAwesomeNonAutoclosure(AwesomeType())
// Not so awesome no autoclosure
// Initialize
// Before
// Description of an awesome type
// After
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment