• 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
Cocoa Bindings and Dependent Keys question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cocoa Bindings and Dependent Keys question


  • Subject: Cocoa Bindings and Dependent Keys question
  • From: Kelvin Chung <email@hidden>
  • Date: Sat, 30 May 2009 14:18:27 -0600

I seem to have a very simple question, but the answer is eluding me for some odd reason, but here goes:

Suppose I have two NSArrayControllers, ac1 and ac2. Suppose now that I have a third controller ac3, whose content array is dependent on both
ac1.selection and ac2.selection (or some keypath therein). Since I can't bind ac3 to both ac1 and ac2 at the same time, I have a class
which has a dependent key. In particular, suppose I have the following:


@interface Foo {
   IBOutlet NSArrayController* ac1;
   IBOutlet NSArrayController* ac2;
}
/* ... */
@end

@implementation Foo
- (id) ac1Selection { return [[ac1 selection] valueForKey:@"bar"]; }
- (id) ac2Selection { return [[ac2 selection] valueForKey:@"baz"]; }

+ (NSSet*) keyPathsForValuesAffectingAc3ContentArray {
   return [NSSet setWithObjects:@"ac1Selection", @"ac2Selection", nil];
}

- (NSArray*) ac3ContentArray {
   /* Do stuff using -ac1Selection and -ac2Selection */
}
@end

(I hope I wired the ac3ContentArray key dependency correctly...)

The part where I'm not getting is how to represent the fact that - ac1Selection, say, is dependent on ac1.selection. Is it as simple as implementing +keyPathsForValuesAffectingAc1Selection as something like...

+ (NSSet*) keyPathsForValuesAffectingAc1Selection {
   return [NSSet setWithObjects:@"ac1.selection", nil];
}

... or do I have to do something more complicated?

On the side, suppose we also have things the other way around: if ac3 has some attribute with some keypath that could alter the selection of ac1 and ac2, what should I do? (Related to this: what if ac2 itself depends on ac1?)

_______________________________________________

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: Cocoa Bindings and Dependent Keys question
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: Message from view to viewController
  • Next by Date: Re: Showing more warnings possible in Xcode?
  • Previous by thread: Re: Modeling "Smart Playlists"
  • Next by thread: Re: Cocoa Bindings and Dependent Keys question
  • Index(es):
    • Date
    • Thread