Create a gist now

Instantly share code, notes, and snippets.

Embed
cleanup actions using defer
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