struct Notification { let postImageURL: String? let postID: String? var userIsFollowed = false }
Notification 구조체가 있다고 합시다.
var notifications = [Notification]() { didSet { tableView.reloadData() } }
이 구조체를 이용해서 프로퍼티 감시자를 가진 배열을 하나 만들었습니다.
프로퍼티 감시자는 다음 세가지 모든 상황에서 호출됩니다.
self.notifications = notifications
notifications[index] = Notification()
notifications[index].userIsFollowd = isFollowed
-
프로퍼티 감시자를 가진 변수 자체를 변경해도 호출됩니다.
-
프로퍼티 감시자를 가진 배열의 한 요소 자체를 변경해도 호출됩니다.
-
그 요소가 가진 프로퍼티를 변경해도 호출됩니다.
보통 1번에 대해서만 설명되어 있는것같아 작성했습니다.
또한 주제와는 맞지 않지만 프로퍼티 감시자는 프로퍼티를 변경시키는 쓰레드에서 호출됨을 기억하면 좋을것같습니다.