• 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: Cocoa-dev Digest, Vol 2, Issue 708
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa-dev Digest, Vol 2, Issue 708


  • Subject: Re: Cocoa-dev Digest, Vol 2, Issue 708
  • From: Glen Low <email@hidden>
  • Date: Tue, 17 May 2005 08:59:02 +0800

Malcolm:

On 17/05/2005, at 3:02 AM, email@hidden wrote:

I've created my own subclass of NSController and called  

exposeBinding for the various bindings available on it. Each  

binding corresponds exactly with a KVC-compliant pair of methods  

e.g. array and setArray.

Now I can easily bind arrays of simple values to the binding.  

However, supposing I have an array of dictionaries, each  

dictionary with a key of "name", I find I cannot bind to  

array.name... it fails at runtime with a

[<NSCFArray 0x3b85e0> addObserver:forKeyPath:options:context:] is  

not supported. Key path: name



is in setting up the observer (before you even get to the stage of  

receiving KVO notifications).  You can't simply observe the array  

keypath, you need to register to observe the objects in the array  

(see for example,  

addObserver:toObjectsAtIndexes:forKeyPath:options:context:).


To clarify, I don't call addObserver:forKeyPath:options:context: myself, rather the NSController/NSObject supplied bind:toObject:withKeyPath: calls it on my behalf.

I managed to avoid this by overriding it like so:

- (void) bind: (NSString*) binding toObject: (id) observableController withKeyPath: (NSString*) keyPath options: (NSDictionary*) options
    {
         if ([binding isEqualToString: @"array"])
            {
                // if I call super here instead, it blows up with the above error...
                 [self setKeys: [observableController valueForKeyPath: keyPath]];    // just get the array value once...
            }
        else
            [super bind: binding toObject: observableController withKeyPath: keyPath options: options];
    }

i.e. preventing the inbuilt bind:ToObject:withKeyPath: from calling through to addObserver:forKeyPath:, although I'm not fully comfortable with this approach since I'm not sure what else bind:ToObject:withKeyPath: is doing under the covers (yes, Malcolm, I've read your warning about calling super in bind:toObject:withKeyPath: on your very helpful web pages.)

Perhaps that is what NSPopUpButton is doing with its array-valued bindings? Is it calling addObserver:toObjectsAtIndexes:forKeyPath: instead in its bind:toObject:withKeyPath: implementation?


Cheers, Glen Low



---

pixelglow software | simply brilliant stuff

www.pixelglow.com

aim: pixglen


 _______________________________________________
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

  • Prev by Date: Re: Docoabrowser for 10.4 is out!
  • Next by Date: Getting options to appear in custom bindings in IB
  • Previous by thread: Re: Docoabrowser for 10.4 is out!
  • Next by thread: Getting options to appear in custom bindings in IB
  • Index(es):
    • Date
    • Thread