struct Notification { let postImageURL: String? let postID: String? var userIsFollowed = false }
Say we have a Notification struct.
var notifications = [Notification]() { didSet { tableView.reloadData() } }
Using this struct, I made an array that has a property observer.
The property observer is called in all three of the following situations.
self.notifications = notifications
notifications[index] = Notification()
notifications[index].userIsFollowd = isFollowed
-
It's called when you change the variable that has the property observer itself.
-
It's called when you change a single element of the array that has the property observer.
-
It's called when you change a property of that element.
It seems like usually only case 1 is explained, so I wrote this up.
Also, it's off topic, but it's good to remember that a property observer is called on the thread that changes the property.