Swift - func viewWillAppear

Cristian C. picture Cristian C. · Aug 19, 2014 · Viewed 59.5k times · Source

I have a standard SingleViewApplication project.

ViewController.swift

import UIKit
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        println("viewDidLoad");
    }
}

When I start the application, viewDidLoad is called.

My scenario:
- press Home button (applicationDidEnterBackground)
- recall application (applicationWillEnterForeground)
and viewDidLoad is not called.

Is there another func to override?

Answer

iDev picture iDev · Oct 28, 2014

If you want to call viewWillAppear in swift use this.

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated) // No need for semicolon
}