Created
February 1, 2016 13:33
-
-
Save petebarber/05826793b66d76410f47 to your computer and use it in GitHub Desktop.
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
enum WhenToReturn | |
{ | |
case After0 | |
case After1 | |
case After2 | |
} | |
func deferTest(whenToReturn: WhenToReturn, shouldBranch: Bool) | |
{ | |
print("Defer Test - whenToReturn:\(whenToReturn), shouldBranch:\(shouldBranch)") | |
defer | |
{ | |
print("defer 0") | |
} | |
print("0") | |
if whenToReturn == WhenToReturn.After0 | |
{ | |
return | |
} | |
defer | |
{ | |
print("defer 1") | |
} | |
print("1") | |
if whenToReturn == WhenToReturn.After1 | |
{ | |
return | |
} | |
if shouldBranch | |
{ | |
defer | |
{ | |
print("shouldBranch") | |
} | |
} | |
defer | |
{ | |
print("defer 2") | |
} | |
print("3") | |
} | |
deferTest(WhenToReturn.After0, shouldBranch: false) | |
deferTest(WhenToReturn.After1, shouldBranch: true) | |
deferTest(WhenToReturn.After2, shouldBranch: false) | |
deferTest(WhenToReturn.After2, shouldBranch: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment