• 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: Why aren't my bindings firing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why aren't my bindings firing?


  • Subject: Re: Why aren't my bindings firing?
  • From: Charles Srstka <email@hidden>
  • Date: Sat, 28 Jun 2008 12:31:56 -0500

On Jun 28, 2008, at 4:55 AM, Ken Thomases wrote:

Yeah, it surprises me, too, that NSObject has an implementation of bind:toObject:withKeyPath:options:. I had thought that it was just part of an informal protocol -- that is, that it was declared in a category on NSObject, but never implemented except by specific classes which adopted that protocol. However, I did a symbol dump of the AppKit framework and I see that there is, in fact, an implementation. I have no idea what it could be doing.

Actually, I gave it a little thought, and perhaps the purpose of NSObject's default implementation is just to make it easier to implement the stuff that's mentioned in that "how bindings work" document. The built-in implementation provides the bindings in one direction for us - all we have to do is supply the bindings in the other direction, so adding an NSMutableDictionary instance variable to the view and then adding these methods:


- (void)bind:(NSString *)key toObject:(id)obj withKeyPath:(NSString *)keyPath options:(NSDictionary *)options {
NSDictionary *binding = [NSDictionary dictionaryWithObjectsAndKeys:key, @"key", obj, @"target", keyPath, @"keyPath", nil];


    [ivar_bindingsDict setObject:binding forKey:key];

    [super bind:key toObject:obj withKeyPath:keyPath options:options];
}

- (void)unbind:(NSString *)key {
    [ivar_bindingsDict removeObjectForKey:key];
}

- (void)fireNotificationsForKey:(NSString *)key {
    NSDictionary *binding = [ivar_bindingsDict objectForKey:key];

    if(binding) {
        id target = [binding objectForKey:@"target"];
        NSString *keyPath = [binding objectForKey:@"keyPath"];

        [target setValue:[self valueForKey:key] forKeyPath:keyPath];
    }
}

and then just calling [self fireNotificationsForKey:@"someKey"] each time you modify whatever it is in the view's state that will cause the binding "someKey" to need to be updated, would pretty much do it, am I right?

(I suppose you'd also want to expose your available bindings by calling +exposeBinding: in your +initialize method and implement valueClassForBinding: if you're going to make an Interface Builder palette for your view)

Charles
_______________________________________________

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


References: 
 >Why aren't my bindings firing? (From: Charles Srstka <email@hidden>)
 >Re: Why aren't my bindings firing? (From: Ken Thomases <email@hidden>)
 >Re: Why aren't my bindings firing? (From: Charles Srstka <email@hidden>)
 >Re: Why aren't my bindings firing? (From: Ken Thomases <email@hidden>)
 >Re: Why aren't my bindings firing? (From: Charles Srstka <email@hidden>)
 >Re: Why aren't my bindings firing? (From: Ken Thomases <email@hidden>)
 >Re: Why aren't my bindings firing? (From: Charles Srstka <email@hidden>)
 >Re: Why aren't my bindings firing? (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Using isMemberOfClass with a tree of subclass of NSManagedObject
  • Next by Date: Re: Using isMemberOfClass with a tree of subclass of NSManagedObject
  • Previous by thread: Re: Why aren't my bindings firing?
  • Next by thread: Help with notifications and NSFileHandle threads
  • Index(es):
    • Date
    • Thread