Sobes.tech
Junior — Middle

When does the addition of a root View occur in the hierarchy when calling the `viewWillAppear` method?

sobes.tech AI

Answer from AI

The viewWillAppear method is called before the root UIView of the controller is added to the view hierarchy and becomes visible on the screen. However, the actual addition of the root View to the hierarchy occurs immediately after the call to viewWillAppear, but before viewDidAppear. That is, when viewWillAppear is called, the root View has not yet been added to the hierarchy, but it will be added right after this call.

This allows you to prepare the interface or update data before the user sees the screen.

Example sequence of calls:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    // Here, view is not yet in the hierarchy
}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    // Here, view has already been added and is visible
}
When does the addition of a root View occur in the… - sobes.tech