Re: Question about model observers
Re: Question about model observers
- Subject: Re: Question about model observers
- From: Ken Thomases <email@hidden>
- Date: Wed, 12 May 2010 13:04:02 -0500
On May 12, 2010, at 11:44 AM, Quincey Morris wrote:
> *All* collections emit KVO notifications when their contents change, in the sense of objects entering or leaving the collection. Add, remove and replace for arrays, add and remove for sets, set and remove for dictionaries.
Arrays and sets may (probably; I haven't checked) emit change notifications for their "count" and "description" properties when elements are added or removed. But they don't emit change notifications regarding the specific elements that they contain, which is what I think Keary was getting at. In particular, they don't emit a change notification of kind NSKeyValueChangeInsertion, NSKeyValueChangeRemoval, or NSKeyValueChangeReplacement.
> Perhaps the difference between dictionaries and other collections is this: There is no way to *name*, via a KVC keypath, the objects in an array or set. There *is* a way to name via keypath the objects in a dictionary.
It's deeper than that. It's not just a matter of naming. It may indeed be too early in the morning for you, since I'm sure you know the following: KVO reports changes to a _property_ of an _object_. Both pieces, object and property, are part of the change notification. Elements of an array or set are not properties of the collection; they are merely elements.
What invocation(s) of -observeValueForKeyPath:ofObject:change:context: would you expect to flow from the addition or removal of an element to an array or set? What would the arguments be?
> *No* collections (AFAIK) emit KVO notifications when their contained objects change (that is, when a property of a contained object changes). They can't, in general, because there's no general definition of what it means for an object to "change". (Some properties might change but not be regarded as the object changing; some internal state might change with no change in properties.)
Agreed, and I don't think anybody was suggesting that.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden