• 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 on a key path with nil intermediate properties
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO on a key path with nil intermediate properties


  • Subject: Re: KVO on a key path with nil intermediate properties
  • From: Rick Mann <email@hidden>
  • Date: Wed, 26 Jun 2013 18:56:20 -0700

Hmm, after all that, it seems that it's actually behaving the way I would expect. Sorry for the noise.

On Jun 26, 2013, at 18:51 , Rick Mann <email@hidden> wrote:

> I've looked through the docs and googled, but I can't find an answer to this question, so if it's obvious, forgive me.
>
> Can one set up KVO on a property of a property if the intermediate one is nil, and then get notified when either changes? In practice, it seems not, as I don't get notified for either the intermediate property or the leaf property. In that case, it seems that I have to observer the intermediate properties individually, and then when those change, ignore and observe their sub properties.
>
> Let's say I have three classes, A, B, and C. A has a b* b property, and B and C have properties foo and bar, respectively:
>
>    @interface B : NSObject
>
>    @property (strong) NString*     bar;
>
>    @end
>
> ---
>
>    @interface A : NSObject
>
>    @property (strong) B*           foo;
>
>    @end
>
> ---
>
>
> Can I do:
>
>    @implementation SomeClass
>
>    - (void)
>    observeValueForKeyPath: (NSString*) inKeyPath
>        ofObject: (id) inObject
>        change: (NSDictionary*) inChange
>        context: (void*) inContext
>    {
>        if ([inKeyPath isEqualToString: @"foo.bar"])
>        {
>            // Yay!
>            //  Notified when a.foo changes
>            //  Notified when a.foo.bar changes
>        }
>        else
>        {
>            [super observeValueForKeyPath: inKeyPath ofObject: inObject change: inChange context: inContext];
>        }
>    }
>
>    - (void)
>    test
>    {
>        A* a = [[A alloc] init];
>
>        [a addObserver: self
>            forKeyPath: @"foo.bar"
>            options: NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
>            context: NULL];
>
>        ...
>
> And be notified in these two instances:
>
>        ...
>
>        B* b = [[B alloc] init];
>        a.foo = b;  //  Notified because foo changed from nil to something
>
>        b.bar = @"something";   //  Notified because bar changed
>    }
>
>
>
>
> --
> Rick
>
>
>
>
> _______________________________________________
>
> 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


--
Rick




_______________________________________________

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 on a key path with nil intermediate properties (From: Rick Mann <email@hidden>)

  • Prev by Date: KVO on a key path with nil intermediate properties
  • Next by Date: voiceover question
  • Previous by thread: KVO on a key path with nil intermediate properties
  • Next by thread: Re: KVO on a key path with nil intermediate properties
  • Index(es):
    • Date
    • Thread