Created
October 23, 2020 05:10
-
-
Save inamiy/4870938e558ff5f1313216b6512ab97f to your computer and use it in GitHub Desktop.
Swift do-defer-guard https://twitter.com/inamiy/status/1319505960583393280
This file contains 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
/// 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