Quick Notes: Designated Init vs Convenience Init

Navati
Mar 5, 2021

--

Photo by Juanita Swart on Unsplash

“It was the rainbow gave thee birth, and left thee all her lovely hues.” — W.H. Davies

Designated Initializer (delegates up 🆙 )

  • default initializer
  • typically there is only one in a class
  • but there definitely has to be one at least !!
  • seen as a funnel point

Rules 📏

  • designated init must call super class’ designated init! (inheritance)
  • designated init must delegate up! ⬆️

Convenience Init (delegates across)

  • secondary / supporting init
  • has the keyword ‘convenience’

Use Case 🧰

  • provide default values for some initializers
  • specific use case

Rules 📏

  • delegates across: must call another init in the same class!
  • ultimately must call a designated init!

--

--

Navati

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