• 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: Why do I receive KVO notification when new value IS the old value?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why do I receive KVO notification when new value IS the old value?


  • Subject: Re: Why do I receive KVO notification when new value IS the old value?
  • From: Jerry Krinock <email@hidden>
  • Date: Wed, 8 Jul 2009 17:18:10 -0700


On 2009 Jul 08, at 16:20, Quincey Morris wrote:

Excuse me while I put on my properties-are-behavior crusader's hat. :)

OK, I get it. Since we don't always use @synthesize, @dynamic, or Xcode's "Scripts" menu (noting the if() test in this implementation) ...


- (void)setName:(NSString *)value {
    if (name != value) {
        [name release];
        name = [value copy];
    }
}

the property can be a behavior.

When undoing an action, all setters that were called during the action need to be called again, in the correct order, even if the getter value doesn't change as a result.

Maybe this is one of the reasons why it is quite common nowadays that when a user clicks "Undo" 10 times, something is seen to happen on only 5 or 6 of the clicks.


On 2009 Jul 08, at 16:49, Kiel Gillard wrote:

To prevent this behaviour, you could override setName: to only change the value when the pointers are not the same.

In other words, return before the -willChangeValueForKey tells KVO about it. Actually, I've done that on occasion. Yes, the filtering can be done on the front end instead of the back end. That's a good thing to keep in mind.


Thanks to all who replied. I don't feel so bad about having to do the filtering now.

_______________________________________________

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: Why do I receive KVO notification when new value IS the old value?
      • From: Graham Cox <email@hidden>
References: 
 >Why do I receive KVO notification when new value IS the old value? (From: Jerry Krinock <email@hidden>)
 >Re: Why do I receive KVO notification when new value IS the old value? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Why do I receive KVO notification when new value IS the old value?
  • Next by Date: Re: Why do I receive KVO notification when new value IS the old value?
  • Previous by thread: Re: Why do I receive KVO notification when new value IS the old value?
  • Next by thread: Re: Why do I receive KVO notification when new value IS the old value?
  • Index(es):
    • Date
    • Thread