Re: Can a value transformer get its own registration name?
Re: Can a value transformer get its own registration name?
- Subject: Re: Can a value transformer get its own registration name?
- From: Jim Correia <email@hidden>
- Date: Thu, 12 Apr 2007 08:44:31 -0400
On Apr 12, 2007, at 8:36 AM, Bill Cheeseman wrote:
But it doesn't explain how to specify the number that is to be used
as the
multiplier when a given instance of a "generalized" value
transformer is
registered. How should I do that? (I know I could write separate
non-generalized transformers for each multiplier, but the point
here is how
to write a single generalized transformer for all multipliers.)
The same way you'd do for any other object. You write a subclass of
NSValueTransformer with per instance state. Instantiate one, and
register it.
MultiplicationValueTransformer *transformer =
[[MultiplicationValueTransformer alloc] initWithMultiplicationFactor:
2];
[NSValueTransformer setValueTransformer: transformer forName:
@"MultiplyByTwoTransformer];
[transformer release];
If you really need to know what name you are registered as (you may
not be registered at all, or may be registered multiple times) you
can use +valueTransformerNames to iterate over the registered
transformers.
If a specific instance of a value transformer knew its own
registration
name, this would be easy. In my generalized transformer's -
transformedValue:
override, I would write: if ([myName
isEqualToString:@"MultiplyByTwoTransformer") myMultiplier = 2. But
I don't
see a -registeredName method in NSValueTransformer.
Bleck :-). Just store that state in your subclasses iVars.
Jim
_______________________________________________
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:
This email sent to email@hidden