When to use unowned reference instead of weak! Top Developer’s secret that you didn’t know

Use unowned when it should not be nil

unowned example

Lazy initialization

Lazy Initialization

Conclusion

  • Use weak when you don’t know what to use. (In most cases, it’s fine)
  • Use unowned when you are sure that it’s not nil
  • Use unowned on lazy initialization

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
KD Knowledge Diet

KD Knowledge Diet

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!