What are property observers in Swift?

Property observers observe and respond to changes in property’s values. They are called every time when a value is set(even when the new value is same as old value). We can add property observers to any stored property(except lazy stored property), inherited property(by overriding the property within subclass) (for both stored and computed property).

We can define either one or both of the following observers on property.

  • willSet
  • didSet

More about willSet and didSet property observers…

Example Swift code using willSet, didSet property observer…

Leave a Reply

%d bloggers like this: