• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: KVO question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO question


  • Subject: Re: KVO question
  • From: Gerd Knops <email@hidden>
  • Date: Wed, 18 Nov 2015 09:36:08 -0600

One possible issues is that `self.thingy=x;` will trigger two change notifications for `thingy`: one for `self.dictionaryOfThings = temp;` (due to keyPathsForValuesAffectingThingy), and one when the setter exits. Depending one what your observer does this may have unforeseen side effects.

A possible workaround would be to replace `self.dictionaryOfThings = temp;` with `_dictionaryOfThings = temp;`.

Gerd


>
> On Nov 17, 2015, at 19:18, Graham Cox <email@hidden> 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@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


_______________________________________________

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


References: 
 >KVO question (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: KVO question
  • Next by Date: Re: Assigning an element of a swift array to a userdata parameter triggers didSet
  • Previous by thread: Re: KVO question
  • Next by thread: NSXMLDocument & friends coalesce runs of spaces to one
  • Index(es):
    • Date
    • Thread