我很好奇,但可以使用自定義鍵(和手動更改通知)來實現KVO嗎?使用KVO與自定義鍵
因此,舉例來說,我可以這樣註冊:
[myObject addObserver:self forKeyPath:@"My custom string" options:0 context:nil];
,併發出這樣的變更通知:
[self willChangeValueForKey:@"My custom string"];
// do something
[self didChangeValueForKey:@"My custom string"];
我在一個小的測試應用程序嘗試了這一點,它的工作原理,但我很好奇是否有人使用過或看過它的價值。
你也可以使用NSNotificationCenter這樣的東西。 – CrimsonChris