Skip to content

Instantly share code, notes, and snippets.

@joanmolinas
Last active August 29, 2015 14:23
Show Gist options
  • Save joanmolinas/8dd62ad0a351104882d0 to your computer and use it in GitHub Desktop.
Save joanmolinas/8dd62ad0a351104882d0 to your computer and use it in GitHub Desktop.
var numbers = [Int]()
func appendNumbers() {
numbers.append(3)
//: defer{} is executed in the final on the function
//: use defer{} when you want that any code run it always whatever the function result
defer {numbers.append(4)}
numbers.append(5)
}
numbers.append(1)
numbers.append(2)
appendNumbers()
numbers.append(6)
//OUTPUT
numbers -> [1, 2, 3, 5, 4, 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment