开发者

Helper classes/libraries to make use of KVC/KVO on iOS more practical/safe?

This question is really looking for a specific class that I know exists, but cannot find.

A few weeks ago I read through an article outlining a helper class for using KVC - it let you encapsulate KVC subscriptions so that you could have multiple values being observed without having to go through the same hander method, and also made cleanup of the KVC observers safer (since KVC cleanup is really finicky and exception prone).

So, in re开发者_开发技巧sponses I am looking for either that helper class I had run across before, or other examples of attempts to wrap KVC to make it safer and more palatable for general use.


I finally found what I was looking for, the key to searching was to look for examples of using KVO with blocks.

I found three interesting resources, which I'll present as a starting point - if anyone has others that are good please also answer.

The first link is the article I mentioned finding before. It has a great summary of the problems with KVO as it stands, and an interesting helper class that encapsulates a KVO session:

http://www.mikeash.com/pyblog/key-value-observing-done-right.html

The second is a simpler NSObject category that lets you pass in a block to be activated on a change notification:

http://blog.andymatuschak.org/post/156229939/kvo-blocks-block-callbacks-for-cocoa-observers

The last is another category on NSObject that uses a binding mechanism to add observation:

http://wirestorm.net/blog/2011/05/27/block-based-observation-with-kvo/


A more up-to-date implementation is facebook kvo implementation using block It added a NSObject Category to add a KVOController property on all objects. But then we should be more careful about the retain cycles problem.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜