Reputation: 3
I would like to add a NSDictionary into a NSManagedObject Category class (or the NSManagedObject class itself) When I do this, and I try to access the property, an exception is thrown.
Is this actually possible? I can't add this property as transient in the model because there is no NSDictionary Data Type, of course.
Thanks!
Upvotes: 0
Views: 386
Reputation: 4767
Using transformable
is the way. Below are few more insights on the transformable property.
The Transformable data type is a special data type that allows us to create attributes based on an Objective-C class (custom objects). This data type is heavily used for storing instances of UIImage, UIColor, and so on. As the information stored in the persistent store has to be in the form of NSData instance, while using Transformable data type, we need to create Value Transformers to convert the custom object (information in attribute of Transformable data type) into an instance of NSData (before storing in the persistent store) and to convert the instance of NSData back to custom object while retrieving from the persistent store.
Upvotes: 0
Reputation: 119031
You don't say how you have currently created the property or what the exception is, but from the description you give it sounds like you should be setting the attribute in the Core Data model to be transformable
. Setting it to be transformable
will cause the NSDictionary
to be archived (and unarchived) as you use it using the standard NSCoding
protocol. Be sure that everything you put into the dictionary supports the NSCoding
protocol so that it is properly archived and restored.
Upvotes: 1