• 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, design and documentaion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO, design and documentaion


  • Subject: Re: KVO, design and documentaion
  • From: Bill Bumgarner <email@hidden>
  • Date: Sat, 27 Jan 2007 20:20:34 -0800

Also, in general you must be careful with registering and unregistering:

1)
[object removeObserver:observer forKeyPath:@"test"]; // CRASH!!!
[object addObserver:observer forKeyPath:@"prop" options:0 context:NULL];


2)
[object addObserver:observer forKeyPath:@"prop" options:0 context:NULL];
[object removeObserver:observer forKeyPath:@"test"]; // SAFE!!!


As long as 'object' remains registered for some other key path, using
removeObserver: is safe. (I guess you could abuse that knowledge).

Have you registered 'observer' as an observer of the @"test"? keypath?

I suspect not. In such a case, the behavior of KVO appears to be undefined.

I would bet that the crash from (1) is because the underlying KVO has nothing in its internal bookkeeping tables related to the observer and, thus, it ends up passing NULL to some random function -- CFRetain (), perhaps -- that can't deal.

That (2) works is merely coincidental. The behavior is still undefined (as far as I could find in the docs), but it happens not to crash in this case.

Now, this fragility may come as a slight surprise. However, KVO is designed to be really really fast and, as such, loading it up with a boatload of assertions and validation code would just slow it down.

b.bum
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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: 
 >Re: KVO, design and documentaion (From: Matt Neuburg <email@hidden>)
 >Re: KVO, design and documentaion (From: patrick machielse <email@hidden>)
 >Re: KVO, design and documentaion (From: "The Karl Adam" <email@hidden>)

  • Prev by Date: Re: KVO, design and documentaion
  • Next by Date: Setting NSDatePicker to display 24-hour time
  • Previous by thread: Re: KVO, design and documentaion
  • Next by thread: Re: KVO, design and documentaion
  • Index(es):
    • Date
    • Thread