开发者

KVO versus NSNotifications [duplicate]

This question already has an answer here: NSNotification VS KVO (1 answer) 开发者_如何学Python Closed 8 years ago.

Is there any advantage to use KVO instead of the more "generic" (and to my opion more robust) feature of NSNotifications ?


I hate KVO with passion, mainly because it forces me to route all KVO notifications through a single handler. I use whatever else available if I have the choice. But KVO has the distinct advantage of being available for many of the classes in the standard library – if you want to observe property changes on some classes from the standard library, KVO might be your only option. There is one very interesting thread on Cocoa Builder about KVO and various observing and binding options.

(I should add that I only have gripes with KVO as a high-level observation interface. I think it’s very good as plumbing for other technologies, especially bindings.)


In order to use NSNotifications todo something similar to KVO you would have to write custom boilerplate accessor methods for every property you wanted to observe.

This is both much less "generic" and much less robust than using KVO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜