Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 responses 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.

like image 811
Kendall Helmstetter Gelner Avatar asked Jul 29 '11 16:07

Kendall Helmstetter Gelner


2 Answers

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/

like image 153
Kendall Helmstetter Gelner Avatar answered Nov 15 '22 06:11

Kendall Helmstetter Gelner


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.

like image 35
Qiulang 邱朗 Avatar answered Nov 15 '22 07:11

Qiulang 邱朗