Re: Trying to bind to reverseTransformedValue: in IB
Re: Trying to bind to reverseTransformedValue: in IB
- Subject: Re: Trying to bind to reverseTransformedValue: in IB
- From: Sam Stigler <email@hidden>
- Date: Sat, 26 Jan 2008 19:47:47 -0800
Kyle,
Thanks for the response. I understand what a value transformer is,
and I've actually implemented -allowsReverseTransformation and -
reverseTransformedValue in all three of my transformers. The
transformers are:
• Binary --> hex
• Binary --> decimal
• Hex --> decimal
Thanks to your explanation, I now see that I should have structured
the transformers a little differently, and I might go back and rework
them (or at least swap the -reverseTransformedValue and -
transformedValue methods). But for simplicity's sake, is it possible
to accomplish what I was originally asking -- to set up the binding to
use -reverseTransformedValue instead of -transformedValue, and vice-
versa?
Thanks again,
Sam
On Jan 26, 2008, at 7:25 PM, Kyle Sluder wrote:
A value transformer is essentially a function which maps values of one
type to values of another type. If you can supply the inverse
function as well, then you do so using -allowsReverseTransformation
and -reverseTransformedValue:. This allows Cocoa to use your value
transformer to set values as well as transform them, but the reverse
transformation is actually a function (in the mathematical sense).
So for your app, you would probably want to store an NSNumber as your
model. Then, you would have three value transformers that would
essentially be the following functions: Number --> String (base 10),
Number --> String (base 16), Number --> String (base 2). You would
provide the reverse transformations in these value transformers as
well, since there is a functional relationship between a string of
digits and a number. Cocoa will use the model type --> view type
binding (Number --> String) for display, and then use the inverse
(String --> Number) for storage.
So your question about "binding reverseTransformedValue" doesn't
make any sense.
HTH,
--Kyle Sluder
_______________________________________________
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