I've run into a frustrating feature of KVO: all notifications are funneled through a single method ( observeValueForKeyPath:....
), requiring a bunch of IF statements if the object is observing numerous properties.
The ideal solution would be to pass a method as an argument to the method that establishes the observing in the first place, but it seems this isn't possible. Does a solution exist to this problem? I initially considered using the keyPath
argument ( addObserver:forKeyPath:options:context:
) to call a method via NSSelectorFromString
, but then I came across the post KVO Dispatcher pattern with Method as context and the article it linked to which offers a different solution in order to pass arguments along as well (although I haven't gotten that working yet).
I know a lot of people have come up against this issue. Has a standard way of handling it emerged?
Comments
Post a Comment