// block方式的KVO
class PersonK: NSObject {
@objc dynamic var age: Int = 0
var observation: NSKeyValueObservation?
override init() {
super.init()
observation = observe(\PersonK.age, options: .new) {
(person, change) in
print(change.newValue as Any)
}
}
}
var p = PersonK()
p.age = 32
p.setValue(30, forKey: "age")
网友评论