On Jul 2, 2008, at 3:16 AM, Ken Thomases wrote:

As a model object, NSMutableDictionary is somewhat problematic. It is only KVO-compliant if it is modified with setValue:forKey:. Any change made via setObject:forKey:, the NSMutableDictionary primitive method, is not broadcast to observers.

There I go again, spreading misinformation.  *sigh*

I had thought that most NSMutableDictionary methods were not KVO- compliant, but I just ran some tests. They all are! (At least, on Leopard.)

That said, much of what I had said still applies:

*) Exposing an NSMutableDictionary as part of your model violates encapsulation. Yes, you can get KVO notifications of changes to it, but you can't act as a gatekeeper for such changes.

*) It's not possible to observe an NSMutableDictionary for the addition of new keys. You either have to know the keys in advance or observe the set of keys that the dictionary has at a given point in time.

*) If you want to observe all of the keys of a dictionary, you either have to add the observer for each key individually or wrap the dictionary in a class where you can implement a synthetic property like the "anyPreferences" that I suggested. Put another way, you can't set up dependent keys without a custom class. (Hrmm. A category on NSMutableDictionary could provide a +keyPathsForValuesAffecting<Key> method, but wow is that a bad idea.)

Cheers,
Ken
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to