Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can you "bind" two values into one?



I'm sorry this had no subject; that's what happens when you have two email addresses, the list won't accept posts from both of them; and you're posting late at night (-:.


-Sam http://www.stigler.org/sam/wordpress


Begin forwarded message:

From: Sam Stigler <email@hidden>
Date: May 24, 2007 2:28:18 AM GMT+10:00
To: Cocoa Developers Developers <email@hidden>
Cc: Jerry Krinock <email@hidden>

I was going to write out an answer saying it would be very simple, etc. using a set of reverse value transformers and NSString, but then I realized that you can't access ivars from value transformers.
Having realized that, your best option might be, hard as it to say, simply not to use bindings in this case. The other option is to see if you can find a way to subclass whatever you're inserting things into (I assume an NSArrayController) to allow for custom behavior (such as appending text etc.) when something is inserted. If you can find a way to do this, you could write a value transformer for firstName that adds a "_f_" (for example) before it, and another one for lastName that adds a "_l_" before it -- all you'd really need is some hint to know how to manipulate the fullName string. Or, if you don't want to take the risk that your user won't put in that prefix, you could make your transformedValueClass be a dictionary with two values: The original string as passed in, and whether it is a firstName or a lastName. You could then handle those in your custom insert (or add?) method.
I'm sorry, I haven't looked at the documentation for NSArrayController recently. I hope this helps.


-Sam
http://www.stigler.org/sam/wordpress


On May 24, 2007, at 1:44 AM, Jerry Krinock wrote:
Say that I have an NSTableView with two columns, firstName and lastName. Say that some marketing hack insists that I store these combined as one string.


For the last hour, I've been trying to figure out how to bind two table columns such as this to a single string in storage, bidirectionally, using Cocoa bindings. But I keep running into a wall, trying to transform two objects into one. What's the smart way to do this?

Thanks,

Jerry Krinock
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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/sstigler_lists% 40mac.com


This email sent to email@hidden



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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/email@hidden

This email sent to email@hidden
References: 
 >(no subject) (From: Sam Stigler <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.