user3051755 user3051755 - 1 month ago 5
iOS Question

iOS equivalent for onRestart()

What is the iOS equivalent for

onRestart()
used on Android?

onRestart()
is called when current activity is being re-displayed to the user (the user has navigated back to it).

Answer

I believe you need viewWillAppear method:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    //your code here
}

It is called every time right before view is going to be shown. So it will be called when view is shown for the first time as well. If you want to avoid running your code for the first time viewWillAppear is called, you will have to add a flag property and check if it has been set previously.