Instantly share code, notes, and snippets.

What would you like to do?
cleanup actions using defer
func readDesc(_ desc:inout String) throws {
let newDesc = desc
defer {
desc = ""
throw SampleError.sample2(message: "cool error")
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