Question

I've subclassed NSMutableDictioary following mainly this great blog post.

Now in that subclass the dictionary itself subscribes to all its values in order to detect any changes. This bit works just fine and value changes are observed internally in that subclass.

However value changes should then be propagated to observers of the dictionary, i.e. observers of the dictionary (subclass) are supposed to get notified that the dictionary has changed.

Except I cannot figure out how to trigger that KVO notification - using

[self didChangeValueForKey:@"self"];

doesn't seem to have any effect so I'm kinda stuck.

How can an instance of the NSMutableDictionary subclass initiate a change notification for itself?

Was it helpful?

Solution

As already hinted by Ken KVO allows you to observe properties - not an object per se!

The Key-Value Observing Programming Guide states, that

Key-value observing provides a mechanism that allows objects to be notified of changes to specific properties of other objects.

In other words: self can never be observed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top