Skip to content

Instantly share code, notes, and snippets.

@inamiy
Created October 23, 2020 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inamiy/4870938e558ff5f1313216b6512ab97f to your computer and use it in GitHub Desktop.
Save inamiy/4870938e558ff5f1313216b6512ab97f to your computer and use it in GitHub Desktop.
/// Swift do-defer-guard test
func test(pass: Bool) {
do {
print("1. start of scope")
defer { print("3. deferred") }
guard pass else { return }
print("2. end of scope")
}
print("4. lastly")
}
test(pass: true) // Runs 1, 2, 3, 4
test(pass: false) // Runs 1, 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment