Problem accessing category method with bindings

  • Hello,

    I have two categories: one on NSString, and one on ABPerson.

    In IB, I want to use bindings to access my categories methods.

    I can successfully access the new methods on NSString, but I can't
    manage to access the ones on ABPerson.

    I made a minimal project demonstrating my problem :

    http://seriot.ch/temp/BindingCategoryProblem.png
    http://seriot.ch/temp/BindingCategory.zip

    Can anyone help me ?

    Thank you in advance.

    --
    Nicolas Seriot
  • Just adding my brick :

    Indeed this is very strange and may be a bug in AB.framework ?

    I tried several things without success :

    Setup bindings to use an intermediate NSObjectController whose
    content is "Controller"
    Moved awakeFromNib's code to init
    Added [self willChangeValueForKey: @"me"] and [self
    didChangeValueForKey: @"me"]; around [self setValue:[[ABAddressBook
    sharedAddressBook] me] forKey:@"me"]

    None of this works :-/

    Yann Bizeul - yann at tynsoe.org
    Cocoa Developer

    Tynsoe Projects
    BuddyPop - GeekTool - SSH Tunnel Manager - ...
    http://projects.tynsoe.org/

    Le 6 mai 07 à 18:47, Nicolas Seriot a écrit :

    > Hello,
    >
    > I have two categories: one on NSString, and one on ABPerson.
    >
    > In IB, I want to use bindings to access my categories methods.
    >
    > I can successfully access the new methods on NSString, but I can't
    > manage to access the ones on ABPerson.
    >
    > I made a minimal project demonstrating my problem :
    >
    > http://seriot.ch/temp/BindingCategoryProblem.png
    > http://seriot.ch/temp/BindingCategory.zip
    >
    > Can anyone help me ?
    >
    > Thank you in advance.
    >
    > --
    > Nicolas Seriot
    >
  • Hmm, ugly. Turns out ABPerson overrides valueForKeyPath so that it
    can expose the record properties as keys. That seems to short out
    looking for your category methods during key look up time though. I
    got it working by making an ABPerson subclass or, a better idea if
    you're doing a larger project - make your own person class that has
    an ABPerson as a member rather than subclassing it. That said to get
    your code working like you want try the code below which implements
    it's own key path lookup. Then, as early as possible in your app,
    call: [[MyPerson class] poseAsClass: [ABPerson class]];

    @interface MyPerson : ABPerson
    @end

    @implementation MyPerson

    - (id) valueForKeyPath: (NSString*) keyPath
    {
    NSArray *path = [keyPath componentsSeparatedByString: @"."];
    unsigned i, max;
    max = [path count];
    id value = self;
    for ( i = 0; i < max; i++ )
    {
      value = [value valueForKey: [path objectAtIndex: i]];
    }

    return value;
    }

    @end

    On 6-May-07, at 12:47 PM, Nicolas Seriot wrote:

    > Hello,
    >
    > I have two categories: one on NSString, and one on ABPerson.
    >
    > In IB, I want to use bindings to access my categories methods.
    >
    > I can successfully access the new methods on NSString, but I can't
    > manage to access the ones on ABPerson.
    >
    > I made a minimal project demonstrating my problem :
    >
    > http://seriot.ch/temp/BindingCategoryProblem.png
    > http://seriot.ch/temp/BindingCategory.zip
    >
    > Can anyone help me ?
    >
    > Thank you in advance.
    >
    > --
    > Nicolas Seriot
previous month may 2007 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today