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

2

6

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.

Seka answered 29/7, 2011 at 16:17 Comment(0)
S
7

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/

Seka answered 29/7, 2011 at 20:0 Comment(0)
I
1

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.

Irreverence answered 9/12, 2015 at 9:12 Comment(1)
KVOController is awesome! I prefer to use it when I have to implement KVO.Perdurable

© 2022 - 2024 — McMap. All rights reserved.