Created
December 22, 2017 16:44
-
-
Save mahmudahsan/f8855b576a0b9d04e2a2a802a6b4cda5 to your computer and use it in GitHub Desktop.
cleanup actions using defer
This file contains hidden or 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
func readDesc(_ desc:inout String) throws { | |
let newDesc = desc | |
defer { | |
desc = "" | |
} | |
throw SampleError.sample2(message: "cool error") | |
print(newDesc) | |
} | |
var desc = "Life is cool and play is a tool!" | |
try? readDesc(&desc) | |
print("Empty: \(desc)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment