Skip to main content

Posts

Showing posts with the label key-value-observing

Key-Value-Observation — Looking for a more elegant solution to respond to value changes

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?