Note that there are some explanatory texts on larger screens.

plurals
  1. POCan transformable attributes in Core Data entities be pointers to c structs? My transformer is not being called
    primarykey
    data
    text
    <p>I'm trying to make a CoreData-persisted entity. This entity has a few properties, one of which is a non-standard attribute, state. The state attribute is a pointer to a C struct with a few properties in it. Here's what my data model looks like:</p> <p>Entities:</p> <p><strong>MDInstance</strong></p> <p>Attributes:</p> <ul> <li>duration: Integer 16</li> <li>moves: Integer 16</li> <li>name: String</li> <li>state: Transformable. I set the Transformer to MDStateTransformer.</li> </ul> <p>I generated my class and edited the state property. This is what the interface looks like:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;CoreData/CoreData.h&gt; #import "MDState.h" // this is where the State structure is defined @interface MDInstance : NSManagedObject @property (nonatomic, retain) NSNumber * duration; @property (nonatomic, retain) NSNumber * moves; @property (nonatomic, retain) NSString * name; @property (nonatomic) State *state; // note that this is a pointer to a struct @end </code></pre> <p>This is what the implementation looks like:</p> <pre><code>#import "MDInstance.h" @implementation MDGameInstance @dynamic duration; @dynamic moves; @dynamic name; @synthesize state; @end </code></pre> <p>I created a value transformer called MDStateTransformer. The implementation of this is (probably) not important. Suffice it to say I have <code>allowsReverseTransformation</code> returning <code>YES</code>, <code>transformedValueClass</code> returning <code>[NSValue class]</code>, and I've implemented <code>transformedValue:</code> and <code>reverseTransformedValue:</code></p> <p>Lastly, I registered the MDStateTransformer in my AppDelegate's <code>application:didFinishLaunchingWithOptions:</code> like this:</p> <pre><code>MDStateTransformer *transformer = [[MDStateTransformer alloc] init]; [NSValueTransformer setValueTransformer:transformer forName:@"MDStateTransformer"]; </code></pre> <p>If I create a new instance of my MDInstance, set it's attribute -including the state attribute- and then try to save the entity, my transformer is never called. </p> <p>I put a stop point in my transformer's init method and it is being instantiated. I put another in <code>transformedValue:</code> and it the function is not being called.</p> <p>However, if I update my MDInstance so that the state attribute is not a pointer, but is simply a State structure, and I update the transformer to work with a struct and not a pointer, the <code>transformedValue:</code> is called.</p> <p>Is it possible to have a custom attribute on an object which is a pointer to a c struct? If so, any ideas what I'm doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload