Geek Culture
Published in

Geek Culture

Swift: willSet and didSet Made Simple

Execute code when a value changes.

Photo by Philipp Katzenberger on Unsplash

In Swift, willSet and didSet are known as property observers.

A property observer responds to changes in the property. For instance, this code prints a new string that is assigned to the word:

--

--

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
Artturi Jalli

Artturi Jalli

I built a blog from 0 to 350k+ monthly visits in 16 months without SEO.