Is it possible to access the previous / current value of a proxy object using KVO?

I have an NSArrayController and I am using KVO to monitor the old / new values ​​of this select method.

This works great (triggers when the selection changes, normal), except that the items in the change dictionary are null and not the old / new selected object. [arrayController selection] still returns the correct object, but I would like to be able to access the previously selected object if possible (perhaps my workaround would be to observe the selected index and see if that works).

The only possible reason I came across is perhaps because the NSArrayController is a proxy object.

So, is this expected behavior or is something strange going on?

EDIT: I've tried observing only indexes, but that didn't work either. Both old and new keys are still displayed as null.

+1


source to share


3 answers


mmalc Cocoa bindings page says:



The dictionary of changes does not contain old and new meanings. This is not your fault, due to a bug in the controller. This bug will not be fixed for the foreseeable future.

+2


source


For simple KVO (as opposed to bindings) try observing the selectedObjects property instead of the select property. This will give you a simple array of objects instead of the proxy objects used by Cocoa's binding system. I believe the old / new keys should accurately reflect the change in selection in this way.



0


source


Are you using NSKeyValueObservingOptionNew

and NSKeyValueObservingOptionOld

in parameters addObserver:forKeyPath:options:context:

?

If you could show us some code it would be helpful.

0


source







All Articles