2
votes

In my model, I have an attribute transformingString that stores an NSString object as NSData, using the "Transformable" type. In my code, I have an NSString as an dynamic property in my NSManagedObject, and accessing that property automatically invokes the value transformer to convert from NSData to NSString.

In some cases, though, I want to access the raw NSData in my code, without invoking the NSValueTransformer, so I can handle the NSData in a different way for some edge case. How can I do this? I don't think there is any way to just turn off the Transformable type for my Core Data model. I'm hoping there is some way to access the raw NSData directly that is passed into the transformer.

I've tried [self primitiveValueForKey: @"transformingString"] but that also invoked the NSValueTransformer and returns the NSString type. Is there a way to do this?

1
Why do you want to do this without using the value transformer? That is not clear from your question. - quellish
Long story, but the gist is that I was saving a UIKit-specific object in the transformable attribute, but now I need to convert that to something more generic, like NSString, but still appear to my code as the UIKit object (or AppKit object, on the Mac). I've figured out a work-around which isn't as elegant as it could be if I had direct access to the underlying NSData, but would still be good to know. - Z S

1 Answers

0
votes

If i resume you want access a value on a NSManagedObject that is not stored in persistent Store. I suggest you to add a category on your NSManagedObject. In this category declare a property in readonly (for be sure that not use for an other thing). In the implementation return the raw NSData.