I'm trying to use KVO in Swift, but the method "observeValueForKeyPath" is called once.
I tried to use NSNumber
instead of Int
, add all options to addObserver
, but the method is still call once when my view load.
Any idea ?
EDIT: It seems like I found a temporary solution using:
var lifes: Int {
willSet {
willChangeValueForKey("lifes")
}
}
KVO requires dynamic dispatch, so the
dynamic
modifier needs to be added to the property:dynamic var lifes = 0