Reputation: 323
Let's say I have these two classes :
class A {}
class B{
var myA:A?
}
I want to know when that happens:
let b = B()
let a = A()
b.myA = a // <<<---- I want to observe this from my A class
I would also like to know who is the owner(In this case, b
).
Sort of like a didSetSelfAsAProperty(ofOwner:AnyObject).
What I am trying to achieve: We have MVVM architecture in our project. I noticed that I need to set both directions when initializing an instance of a view model/view.I need to tell the view model who's its view and vice versa.
Any ideas?
Upvotes: 1
Views: 203
Reputation: 2270
It seems that you're looking for the Observer Pattern. You could achieve it with either callbacks, KVO or third party libraries.
Upvotes: 0