Skip to content

Instantly share code, notes, and snippets.

@petebarber
Created February 1, 2016 13:33
Show Gist options
  • Save petebarber/05826793b66d76410f47 to your computer and use it in GitHub Desktop.
Save petebarber/05826793b66d76410f47 to your computer and use it in GitHub Desktop.
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