Core data transformer direction

  • 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?
  • 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?
  • On Jul 2, 2008, at 10:15 PM, Quincey Morris wrote:

    >> ... 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.
    >
    It's not clear in what way the first paragraph "says that the forward
    transformation is NSData->SomeClass" -- it states that the transformer
    is used "to convert the attribute to and from an instance of NSData"
    -- at worst it's ambiguous.  The second paragraph makes a definite
    statement that is unambiguous.
    See also:
    <http://developer.apple.com/documentation/Cocoa/Reference/CoreDataFramework/
    Classes/NSAttributeDescription_Class/Reference/Reference.html#//apple_ref/d
    oc/uid/TP30001175-SW3
    >

    mmalc
  • On Jul 2, 2008, at 23:37, mmalc crawford wrote:

    > It's not clear in what way the first paragraph "says that the
    > forward transformation is NSData->SomeClass" -- it states that the
    > transformer is used "to convert the attribute to and from an
    > instance of NSData" -- at worst it's ambiguous.  The second
    > paragraph makes a definite statement that is unambiguous.

    Yes, I ended up saying that apparently the documentation can be read
    as literally correct, but it's a *little* bit more than ambiguous --
    because it's also surprising, given the way it's worded, that there's
    no "default" to-NSData transformer, just default behavior that happens
    to use the from-NSData transformer NSKeyedUnarchiveFromData as an
    implementation detail. Since '[attributeDescription
    setValueTransformerName: NSKeyedUnarchiveFromDataTransformerName]'
    won't work, why mention NSKeyedUnarchiveFromDataTransformerName at all?

    But that's beside the point. I wasn't trying to beat up the
    documentation, just asking for clarification/confirmation.
previous month july 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today