It seems like it *should* work. Are you sure you don’t have a typo in your addObserver: method? Considering that you’re using the dictionary’s property setter, keyPathsForValuesAffecting<Key> shouldn’t even be necessary. When I apply KVO, I try to mitigate the potential unsafely of key paths strings by using NSStringFromSelector() whenever possible.
[self.foo addObserver:self forKeyPath:NSStringFromSelector(@selector(bar)) options:NSKeyValueObservingOptionNew context:NULL]; Dan On Nov 17, 2015, at 5:18 PM, Graham Cox <[email protected]<mailto:[email protected]>> 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? Here’s the kind of code I have: @property (retain) id<NSObject> thingy; @property (retain) NSDicitonary* dictionaryOfThings; @implementation - (void) setThingy:(is<NSObject> thing { NSMutableDictionary* temp = [self.dictionaryOfThings mutableCopy]; [temp setObject:thing forKey:kThingKey]; self.dictionaryOfThings = temp; } - (id<NSObject>) thingy { return [self.dictionaryOfThings objectForKey:kThingKey]; } + (NSSet*) keyPathsForValuesAffectingThingy { return [NSSet setWithObject:@“dictionaryOfThings”]; } So what I want (expect?) is that is code sets -dictionaryOfThings directly, an observer of ‘thingy’ will be triggered. Is that right? —Graham _______________________________________________ Cocoa-dev mailing list ([email protected]<mailto:[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<http://lists.apple.com> Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/dstenmark%40opentable.com This email sent to [email protected] _______________________________________________ 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
