Last active
July 29, 2018 00:25
-
-
Save LucianoPAlmeida/fcb12e91dcf166304567ef5d46501b3c to your computer and use it in GitHub Desktop.
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
// 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