Re: what about registering a transformer in the transformer?
Re: what about registering a transformer in the transformer?
- Subject: Re: what about registering a transformer in the transformer?
- From: Keary Suska <email@hidden>
- Date: Wed, 06 Dec 2006 13:16:34 -0700
- Thread-topic: what about registering a transformer in the transformer?
on 12/6/06 12:17 PM, email@hidden purportedly said:
> I have a bunch of transformers. In order to use them, I have to
> initialize them, autorelease, then register. I am guessing (since
> autorelease works) that setValueTransformer retains my transformer. I
> am also guessing that the bindings system is asking the
> NSValueTransformer valueTransformerForName: and passing the name I
> use in IB (which makes me wonder if I can register using a different
> name - I always use the class name - but that's beside the point).
That is my understanding as well. I would add that I am pretty sure that the
call to valueTransformerForName: only happens once for a controller (per nib
load), but exactly when I am not sure.
> So I always have to paste this code into +initialize of the class
> that uses the transformer and I'm looking for a better way
In my understanding, the principle of using +initialize is to ensure that
the transformer is universally available, and of course registered before it
is ever asked for. Where you put the registration code shouldn't matter as
long as that class' +initialize is called before any other object may ask
for the transformer.
> I though that there's no reason I can't register a transformer in
> +initialize of the transformer but then it probably won't be
> registered when it's needed (which would be the reason I was looking
> for).
There could be a number of problems with this approach. If you are looking
to save extra lines of code, I suppose you could register the transformer in
its -init method, but you still need to make sure you init the transformer
at a point before it may be used.
> Anyone have any good ideas? A simple object that just registers
> all my transformers? It still has to be called but it's one line vs
> two for each transformer pasted in. [TransformerRegistrar register]
> is easy to remember too. What do you guys do?
I don't know whether there is some super-elegant way--but I think there are
some approaches that may be better than others. I usually create/register
all transformers in my "AppController" class (following the Application
Controller OOP pattern). My take is that by keeping them all in one place,
they are easier to find and manage. I tend to do the same thing with global
variables, types, and #defines. Also I know that my AppController's
+initialize will always be called first--being the NSApp delegate--so I
don't have to be concerned about where/when I use the transformers.
Best,
Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"
_______________________________________________
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