Re: Question about model observers
Re: Question about model observers
- Subject: Re: Question about model observers
- From: Quincey Morris <email@hidden>
- Date: Wed, 12 May 2010 09:44:34 -0700
On May 12, 2010, at 06:32, Keary Suska wrote:
> On May 11, 2010, at 7:48 PM, Ken Thomases wrote:
>
>> On May 11, 2010, at 10:17 AM, Keary Suska wrote:
>>
>>> ... no collection will ever emit a KVO notification that its contents have changed ...
>>
>> Depends on whether you consider a dictionary a collection or not. NSMutableDictionary does emit KVO notifications when its contents change.
>>
>> I suspect you were thinking of sets and arrays, in which case you're correct.
>
> Yes, this is an important distinction. I often forget about dictionaries since, in my mind, they behave much more like regular objects and themselves tend to represent properties rather than relationships. But they are a collection, and they will emit KVO notifications for contents.
Wait. This made sense the first time I read it, but now I think it doesn't. (Or possibly it's too early in the day for higher brain functions.)
*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.
*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.)
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.
Therefore, there is no way* to observe via a keypath that goes through an array to the properties of its contained objects. There is a way to observe via a keypath that goes through a dictionary.
*Except in the special case of the "funny" keypaths used in bindings such as NSTableView column bindings. Such keypaths do go through an array, naming just the array and a contained object property, without naming the contained object. This only works because the binding (presumably) resolves this into valid KVO observations of the objects in the array._______________________________________________
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