Defer statements

The defer statement lets you run code just before the program exits the current scope. This is a great way to dispose of resources or close network connections:

func printMessage() {
    print("First message")
    defer {
        print("Second Message")
    }
    print("Third message")
}
printMessage()

This is what will appear in the console:

First message
Third message
Second Message
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.90.141