• 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: patrick machielse <email@hidden>
  • Date: Sat, 27 Jan 2007 14:12:37 +0100

Op 27-jan-2007, om 00:44 heeft Matt Neuburg het volgende geschreven:

The other big thing about KVO is that all notifications are funneled thru a
single bottleneck, whereas with true notifications you get to say what
method should be called by a given notification. We had a big discussion of
this back here:


<http://www.cocoabuilder.com/archive/message/cocoa/2006/7/14/167622>

Interesting discussion, I hadn't turned that up during my search for information. The callback design is a bit Javaesque...


My own problems with KVO were caused by repeatedly calling

[receiver addObserver:self ...]

on the same receiver over time, resulting in more and more notifications for each change, leading to severe performance degradation. The KVO implementation could have been more intelligent about this by ignoring duplicate registrations.

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).

The whole implementation of KVO seems a bit awkward, and as a result its correct use requires more attention than I initially expected.

patrick
_______________________________________________

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


  • Follow-Ups:
    • Re: KVO, design and documentaion
      • From: "The Karl Adam" <email@hidden>
References: 
 >Re: KVO, design and documentaion (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Strange results when converting NSDate timeIntervalSinceReferenceDate to NSPoint
  • Next by Date: Re: transparent background in Quartz Composition
  • Previous by thread: Re: KVO, design and documentaion
  • Next by thread: Re: KVO, design and documentaion
  • Index(es):
    • Date
    • Thread