• 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
Can a value transformer get its own registration name?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Can a value transformer get its own registration name?


  • Subject: Can a value transformer get its own registration name?
  • From: Bill Cheeseman <email@hidden>
  • Date: Thu, 12 Apr 2007 08:36:26 -0400
  • Thread-topic: Can a value transformer get its own registration name?

The Value Transformer Programming Guide explains, in the Registering
section, how to register separate instances of a generalized value
transformer under different names.

It goes on to say:

"This allows a value transformer that provides a generalized functionality
to be registered multiple times, with different parameters, for different
names. For example, you could write a MultiplicationTransformer and specify
the number that is used as the multiplier when an instance is initialized.
Separate instances could be registered as ³MultiplyByTwoTransformer²,
³MultiplyByTenTransformer², and so on."

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.)

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.

I suppose I could subclass NSValueTransformer and call it
XXNamedValueTransformer, then implement a -registeredName method myself.

The only other idea I've come up with so far is to put this into the
-transformedValue: override:

if ([self isEqual:[NSValueTransformer
valueTransformerForName:@"MultiplyByTwoTransformer"]]) myMultiplier = 2

This works, so I guess -valueTransformerForName: does not return a separate
copy that would always cause -isEqual: to return NO. This means that this
technique is pretty much as fast as it ought to be, since it's just doing
pointer comparison. Is this what the documentation intended, or is there a
better way?

--

Bill Cheeseman


_______________________________________________

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

  • Follow-Ups:
    • Re: Can a value transformer get its own registration name?
      • From: Nicko van Someren <email@hidden>
    • Re: Can a value transformer get its own registration name?
      • From: Jim Correia <email@hidden>
  • Prev by Date: Re: Force update
  • Next by Date: Re: Can a value transformer get its own registration name?
  • Previous by thread: Re: Getting the context of a context menu
  • Next by thread: Re: Can a value transformer get its own registration name?
  • Index(es):
    • Date
    • Thread