Skip to content

Instantly share code, notes, and snippets.

@mhijack
Created June 18, 2021 22:24
Show Gist options
  • Save mhijack/4a273233c6ce322ad75ef6b12c067246 to your computer and use it in GitHub Desktop.
Save mhijack/4a273233c6ce322ad75ef6b12c067246 to your computer and use it in GitHub Desktop.
func myAutoclosure(auto: @autoclosure @escaping () -> Void) -> () -> Void {
return auto
}
let haha: () -> Void = myAutoclosure(auto: print("haha")) // autoclosure will not be called here even though it looks like we are calling it right away
print("haha should not be called yet")
haha()
print("haha should be called")
// haha should not be called yet
// haha
// haha should be called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment