I have the following struct of properties for Chat
struct Chat {
var id = String()
var gender = String()
var date = Date()
init() {}
}
In a view controller, i declare an instance of Chat called observablechat
, and then i used the flatmap operator to attempt and observe only changes in the date
property of observablechat
. However, if i change the gender property (as shown), the subscription gets triggered. I wonder why that is and how can i fix this code such that the subscription only looks at what happens to the date
property and nothing else?
class ViewController: UIViewController {
var observablechat = Variable(Chat())
observablechat.asObservable()
.flatMap { (Chat) -> Observable<Date> in
return Observable.of(Chat.matchDate)
}.subscribe(onNext: { (r) in
print(r)
}).addDisposableTo(disposeBag)
self.observablechat.value.gender = "male"
//triggers subscription above.
}
}