• 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: Manual KVO and will/didChangeValueForKey
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Manual KVO and will/didChangeValueForKey


  • Subject: Re: Manual KVO and will/didChangeValueForKey
  • From: mmalcolm crawford <email@hidden>
  • Date: Thu, 2 Jun 2005 18:25:41 -0700


On Jun 2, 2005, at 5:42 PM, Andrew White wrote:
- (void) makeAChange
{
    [self willChangeValueForKey: @"property"];
    <change property>
    [self didChangeValueForKey: @"property"];
}

Is the property an instance variable? If so, you should implement and use appropriate accessor methods.

- (void) observeValueForKeyPath: (NSString *) keyPath
    ofObject: (id) object
    change: (NSDictionary *) change
    context: (void *) context
{
    if (object == _a)
    {
        if ([keyPath isEqualToString: @"property"])
        {
            [self willChangeValueForKey: @"anotherProperty"];
            [self didChangeValueForKey: @"anotherProperty];
            return;
        }
        <...>
    }

Umm, you can't just sprinkle your code with KVO notifications like a magic incantation. Write and use appropriate accessor methods, and if necessary register dependencies with setKeys:triggerChangeNotificationsForDependentKey:. It may be the case that there's still a problem after that, but it's much less likely, and it will be a more structured problem to address.

mmalc

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Manual KVO and will/didChangeValueForKey
      • From: Andrew White <email@hidden>
References: 
 >Manual KVO and will/didChangeValueForKey (From: Andrew White <email@hidden>)
 >Re: Manual KVO and will/didChangeValueForKey (From: Tim Lucas <email@hidden>)
 >Re: Manual KVO and will/didChangeValueForKey (From: mmalcolm crawford <email@hidden>)
 >Re: Manual KVO and will/didChangeValueForKey (From: Andrew White <email@hidden>)

  • Prev by Date: Bug in NSImageView / NSPDFImageRep in Tiger?
  • Next by Date: completePathIntoString doesn't work with unicode paths??
  • Previous by thread: Re: Manual KVO and will/didChangeValueForKey
  • Next by thread: Re: Manual KVO and will/didChangeValueForKey
  • Index(es):
    • Date
    • Thread