On Sat, Jun 28, 2008 at 9:35 PM, Owen Yamauchi <[EMAIL PROTECTED]> wrote: > On Sat, Jun 28, 2008 at 6:24 PM, Ben Trumbull <[EMAIL PROTECTED]> wrote: >>> Which is, frankly, a bit goofy and, thus, the primary reason why I >>> would avoid using -valueForKey: on a dictionary. >> >> Amen. It's slower, and people reading your code can get very confused. > > Then is there a recommended way of binding to the contents of > dictionaries? For example, suppose I have an NSObjectController > representing some object, which has an NSDictionary (let's say it's > called "attributes") as a property. Then can I bind to the value > stored under a key in that dictionary? Say I want to bind a text > field's value to whatever is stored under the key "name" in the > "attributes" dictionary. The intuitive (to me) thing to do is bind to > the NSObjectController, controller key "selection", model key path > "attributes.name". But that won't work. Is there a good solution?
Why wouldn't it? The NSObjectController's selection proxy receives the keypath "attributes.name", so it sends -valueForKeyPath:@"attributes.name" to its concrete object (your model object). This object's implementation of -valueForKeyPath: sees that "attributes" is a valid key, so it gets your NSDictionary exposed as "attributes" and sends it -valueForKeyPath:@"name". -valueForKeyPath:'s custom logic treats "name" as a dictionary key first, and returns -objectForKey:@"name". At least this is what I've gathered from Bill and Ben's discussion. --Kyle Sluder _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]