swift defer statement code example
Example 1: defer swift
defer {
print("This will always be printed last")
}
print("Hello, World!")
// Output:
// Hello, World!
// This will always be printed last
Example 2: swift 5 if statement
let a = -5
// if the condition is true then doThis() gets called else doThat() gets called
a >= 0 ? doThis(): doThat()
func doThis() {
println("Do This")
}
func doThat() {
println("Do That")
}