• 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: How to programmatically determine if one object is observing another on a keyPath and context?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?


  • Subject: Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
  • From: Motti Shneor <email@hidden>
  • Date: Sun, 09 Sep 2012 23:50:21 +0300

On 9 בספט 2012, at 22:04, Ken Thomases wrote:

> On Sep 9, 2012, at 4:32 AM, Motti Shneor wrote:
>
>> Hi everyone. This seems a novice question, but I could not find any high-level approach for that.
>>
>> Some details of my special need: I have an NSViewController subclass, that should observe some attribute of its representedObject.
>>
>> However, the representedObject may change to another, become nil  etc.
>
> Why is that a "however"?  What's the problem?  Since the representedObject is KVO-compliant, all observations _through_ that property will automatically follow it as it changes.
>

Nope. When representedObject becomes nil, I DO NOT WANT to observe anything, and I need to remove the observance from the previous representedObject, BEFORE it is set to nil on my NSViewController.

If I added myself as an observer to a specific object, in the following way:

[self.representedObject addObserver:self forKeyPath:@"incomingNotes" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];

than it is MY responsibility to remove myself from that object, just before losing it (e.g. as my representedObject is set to nil).

Motti Shneor, Mac OS X Software Architect & Team Leader
Spectrum Reflections Ltd.



_______________________________________________

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


  • Follow-Ups:
    • Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
      • From: Quincey Morris <email@hidden>
    • Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
      • From: Fritz Anderson <email@hidden>
References: 
 >KVO Question: How to programmatically determine if one object is observing another on a keyPath and context? (From: Motti Shneor <email@hidden>)
 >Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
  • Next by Date: Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
  • Previous by thread: Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
  • Next by thread: Re: KVO Question: How to programmatically determine if one object is observing another on a keyPath and context?
  • Index(es):
    • Date
    • Thread