I have a managed entity that acts like a playlist, it has a lot to do with playlist articles. There may be several playlists, but only one βactiveβ playlist. An active playlist is indicated by the logical attribute of the managed entity.
I have the number of items in the active playlist, displayed as an icon in the tab bar item. The view controller, which represents the tab bar item, listens for a specific notification that is triggered when the contents of the active playlist are updated.
I implemented this in what, in my opinion, is an awkward way and would like to do it better. It works at the moment, but I'm not happy with it.
Currently, every playlist object in awakeFromFetch checks to see if it is active, and if it registers itself (using observing the key value) as an observer for the key path, which is the key for the relationship. When he notices a change, he triggers a notification that causes the tab bar item to update.
If a playlist loses or receives an active state, it stops or starts to monitor itself properly, so notifications are activated only from the active playlist.
I would like to discard all the KVO code that I myself observe, since I am concerned about the various entry and exit points, as well as when you need to add and remove observers accordingly. It seems too dirty.
I would just like to override didChangeValueForKey: check and send my notification there, if necessary, and then call the super implementation. But this is expressly prohibited in the documentation:
didChangeValueForKey:
Called to inform the recipient that the value of this property has changed.
- (void) hasChangeValueForKey: (NSString *) key
Parameters
key
The name of the changed property. Discussion For more information, see Key Value Observation Programming Guide.
You should not override this method.
So what can I do?