如题,记录下swift中监听自定义属性失效的问题 极简单的例子 import UIKit class HZJViewController: UIViewController { var name:String = "one" override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = .white self.addObserver(self, forKeyPath: "name", options: [.old,.new], context: nil) } deinit { self.removeObserver(self, forKeyPath: "name") } override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { if keyPath == "name" { print(change) } } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {