On Nov 17, 2015, at 7:18 PM, Graham Cox <graham....@bigpond.com> wrote:
> 
> I’m using KVO to observe a bunch of properties.
> 
> Most of these properties are split out into simple things that set a single 
> value, but internal to my object, some end up setting a common dictionary of 
> attributes, which is also a property.
> 
> I KVO observe both the simple properties and the common dictionary property. 
> Mostly this is working, but when code directly sets the dictionary property, 
> the other properties don’t trigger their observers, even though I’m 
> implementing the +keyPathsForValuesAffecting<property>, which I believe 
> should cause the additional triggering. Have I understood that right?

If by "code directly sets the dictionary property", you mean always in a 
KVO-compliant manner, then yes.


> @property (retain) id<NSObject> thingy;
> @property (retain) NSDicitonary* dictionaryOfThings;

It's not clear if this is a public or private property.  If it's public, and 
probably even if it's private, this should be a "copy" property, not just 
"retain".  If it's just "retain", you're not protected against somebody setting 
it to a mutable dictionary and then subsequently mutating the dictionary, 
thereby effectively mutating your property in a non-KVO-compliant manner.

All of that said, I agree with Quincey.  You should just use either normal 
properties backed by (compiler-synthesized) instance variables, or you can use 
a secondary object with such properties.  Using a dictionary may seem like a 
quick-and-dirty solution, but invites problems in the long run.

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to