• 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: tearing my hair, ok here is a compilable example.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tearing my hair, ok here is a compilable example.


  • Subject: Re: tearing my hair, ok here is a compilable example.
  • From: Quincey Morris <email@hidden>
  • Date: Wed, 15 Oct 2008 22:54:56 -0700

On Oct 15, 2008, at 22:13, Chris Idou wrote:

@class Class1;
@interface Class2 : NSObject {
   IBOutlet Class1 *class1;


} @property(readonly) Class1 *class1; -(BOOL)myMethod; @end

#import "Class2.h"
#import "Class1.h"

@implementation Class2

@synthesize class1;

...

- (void)awakeFromNib {
   [self addObserver:self
          forKeyPath:@"myMethod"
             options:NSKeyValueObservingOptionNew
             context: [Class2 class]];

}


+ (NSSet *)keyPathsForValuesAffectingMyMethod { NSLog(@"keyPathsForValuesAffectingMyMethod"); return [NSSet setWithObject:@"class1.canLink"]; }

I think your problem is that Class2 isn't properly KVO compliant for the key "class1". Consider what happens when your nib is loaded. At some point, the nib loader needs to set "class1" to its correct value. Since the property is readonly and synthesized, there's no setter method, so the instance variable is changed directly. (I'm going from memory here, but I believe that's what documented to happen.) That presumably fails to trigger any KVO notifications, and your "keyPathsForValuesAffectingMyMethod" is not consulted.


Try this:

...

@interface Class2 ()

@property(readwrite) Class1 *class1;
@end



@implementation Class2

@synthesize class1;
....

If my theory is correct, that should cause the outlet to be set via a KVC-compliant setter, and the keypath dependency should start working.



_______________________________________________

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: tearing my hair, ok here is a compilable example.
      • From: Chris Idou <email@hidden>
References: 
 >tearing my hair, ok here is a compilable example. (From: Chris Idou <email@hidden>)

  • Prev by Date: tearing my hair, ok here is a compilable example.
  • Next by Date: Re: Dial with Bluetooth
  • Previous by thread: tearing my hair, ok here is a compilable example.
  • Next by thread: Re: tearing my hair, ok here is a compilable example.
  • Index(es):
    • Date
    • Thread