View Lifecycle: A Quick Summary

Navati
2 min readFeb 24, 2021
Photo by Simon Berger on Unsplash

view did load, did love, did loathe.

Quick notes on the iOS View Life cycle based on the Apple docs

viewDidLoad()
  • 📞 called only once !
  • 📞 called when content view is created
  • 👀 but it is not necessary that the content view is created when the view controller is instantiated for the first time
  • 🥱 content view is lazily created!
  • 🧰 USE CASE: additional setup
  • 📋 Storyboard — outlets guaranteed to have valid values
viewWillAppear()
  • 📞 called when content view is about to be added to the view hierarchy
  • ⚠️ does NOT guarantee that the content view will be visible
  • view could be hidden or obscured by other views
  • 🧰 USE CASE: any operation before the content view is presented onscreen
viewDidAppear()
  • 📞 called right after the content view is added to the view hierarchy
  • ⚠️ does NOT guarantee that the content view will be visible
  • view could be hidden or obscured by other views
  • 🧰 USE CASE: any operation that needs to take place as soon as the view is presented onscreen
  • eg) fetching data
  • eg) showing an animation
viewWillDisappear()
  • 📞 called when content view is about to be removed from the view hierarchy
  • ⚠️ wont be called just because the content view has been obscured or hidden
  • 🧰 USE CASE: clean up tasks 🧼
  • eg) committing changes
  • eg) resigning first responder status
viewDidDisappear()
  • 📞 called right after the content view is removed from the view hierarchy
  • ⚠️ wont be called just because the content view has been obscured or hidden
  • 🧰 USE CASE: additional tear down activities ✂️

--

--

Navati
Navati

Written by Navati

iOS dev eager to learn + advocate for unrepresented folk in tech. Legacy Leadership Fellow @ WomenWhoCode Mobile + WTM Ambassador.

No responses yet