View controller life cycles

View controllers are responsible for managing a single view hierarchy. The top-level view, containing all of the subviews, is stored in the view property of the view controller.

There are multiple ways to provide a UIViewController with a view:

When displaying a view controller on-screen, whether from a modal presentation, inside a navigation controller, or directly from the application's delegate window, methods will be called to help you manage its life cycle. They are as follows:

These methods are called by UIKit. It is recommended that you avoid calling them manually; and when overriding them, you should always call super. Try to ensure that the life cycles of your view controllers fit inside the UIKit flow.

Now, let's have a look at some anti-patterns that you should avoid with UIViewController.