Re: Core data transformer direction
Re: Core data transformer direction
- Subject: Re: Core data transformer direction
- From: Quincey Morris <email@hidden>
- Date: Wed, 2 Jul 2008 22:51:28 -0700
On Jul 2, 2008, at 22:15, Quincey Morris wrote:
The core data programming guide say this about transformable
attributes:
... Core Data uses an instance of NSValueTransformer to convert the
attribute to and from an instance of NSData. Core Data then stores
the data instance to the persistent store. By default, Core Data
uses the NSKeyedUnarchiveFromDataTransformerName transformer,
however you can specify your own transformer if you want.
... If you specify a custom transformer, it must transform an
instance of the non-standard data type into an instance of NSData
and support reverse transformation.
The first paragraph (and the description of
NSKeyedUnarchiveFromDataTransformerName) says that the forward
transformation is NSData->SomeClass.
The second paragraph says that the forward transformation is
SomeClass->NSData.
Anyone know which is the correct answer?
Actually, I have a horrible feeling the answer is "both". There's some
evidence that if you specify a transformer name in the data model, it
needs to be be SomeClass->NSData, but if you omit the name then Core
Data uses NSKeyedUnarchiveFromData (a NSData->SomeClass transformer)
*backwards*.
For example, Adam Jenkins posted about this in April. He reported that
specifying NSUnarchiverFromData (another NSData->SomeClass
transformer) *didn't* work, but a custom transformer that looks like
it did the same thing in reverse *did* work.
I had the same experience he reported with a NSData->SomeClass
transformer I tried to write: it didn't seem to be called at all. My
guess is that transformedValueClass needs to be NSData, which means
that the transformer must be SomeClass->NSData.
That would mean the documentation is right, but specifying the
"default" transformer (NSKeyedUnarchiveFromData) isn't the same as
allowing the transformer to default, which is a little unnerving.
Does that sound correct?
_______________________________________________
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