• 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: Making a bound view re-read its value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Making a bound view re-read its value


  • Subject: Re: Making a bound view re-read its value
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 15 Aug 2008 15:43:02 -0700

On Aug 15, 2008, at 15:05, Michael Ash wrote:

The problem then is that the empty will/did pair is used as a
*substitute* for the proper calls. It's sometimes too hard to wrap
every change in a will/did pair, so instead people put an empty
will/did call *after* the change. It is this which ends up causing
problems. The "will" call is supposed to happen before the change
takes place, with the old value; that's the whole point of it, why
there's two separate calls. Some mechanisms depend on being able to do
something with both the old and new value, and they depend on you to
provide it (indirectly, by calling "will" before you erase it). Thus
use of an empty will/did pair, unless it's just being useless,
indicates that you have problems with your code which will in turn
cause problems with these mechanisms.

Yes, well, I took several too many shortcuts in the post you're replying to, some of which Markus already pointed out. Another is that my "perfectly legal" setter didn't make sense in the default case, where the willChange/didChange happens automatically and doesn't need to be coded in the setter. A better example would be:


- (NSInteger) xSquared {
	return ivarX * ivarX;
}

- (NSInteger) x {
	return ivarX;
}

- (void) setX: (NSInteger) newX {
      [self willChangeValueForKey:@"xSquared"];
      ivarX = newX;
      [self didChangeValueForKey:@"xSquared"];
}

However, your point is well taken. This variant of the setter:

- (void) setX: (NSInteger) newX {
ivarX = newX;
[self willChangeValueForKey:@"xSquared"]; // bad way to trigger a KVO update for "xSquared"
[self didChangeValueForKey:@"xSquared"];
}


is wrong for the reasons you state.

Lastly, before I shut up, in both Markus's question and the thread that Adam referred to, the idea was to trigger a KVO update when the property value was known to have *not* changed. In those circumstances, I still believe, the "emptiness" of the willChange/ didChange is moot -- if triggering a KVO update is the correct thing to do in that case, then calling willChange/didChange is a valid way to do it in that case.

_______________________________________________

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: Making a bound view re-read its value
      • From: "Michael Ash" <email@hidden>
References: 
 >Making a bound view re-read its value (From: Markus Spoettl <email@hidden>)
 >Re: Making a bound view re-read its value (From: Negm-Awad Amin <email@hidden>)
 >Re: Making a bound view re-read its value (From: Markus Spoettl <email@hidden>)
 >Re: Making a bound view re-read its value (From: "Adam R. Maxwell" <email@hidden>)
 >Re: Making a bound view re-read its value (From: Quincey Morris <email@hidden>)
 >Re: Making a bound view re-read its value (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Expanding outline view item ancestry
  • Next by Date: Re: creating files to write data to?
  • Previous by thread: Re: Making a bound view re-read its value
  • Next by thread: Re: Making a bound view re-read its value
  • Index(es):
    • Date
    • Thread