views:

275

answers:

2

I have created an Entity in CoreData that includes a Transformable attribute type implemented as an NSDictionary. The NSDictionary attribute only contains values of a custom class. The properties of the custom class are all of type NSString. The custom class complies with NSCoding implementing:

-(void)encodeWithCoder:(NSCoder*)coder;

-(id)initWithCoder:(NSCoder *)coder

When saving the Entity for the first time all attributes including the Transformable (NSDictionary) type are properly saved in the DB. When the same Entity is fetched from the DB and updated (including the Transformable attribute) it seems to be updated properly. However, when the app is closed and then reopened fetching the Entity does not show the updated Transformable attribute-type though the rest of the attributes of type NSDate and NSString are up-to-date. The Transformable attribute is the original saved value not the updated value.

Is this a problem with KVO or am I missing something else when trying to save an NSDictionary filled with a custom class to CoreData?

+2  A: 

Are you setting the value back into the NSManagedObject? The NSManagedObject will not watch for changes to the transformable object. You need to call the appropriate setter before saving.

Marcus S. Zarra
+1  A: 

I ran into the same problem and ended up switching to NSDictionary as transformable attribute instead of NSMutableDictionary. Just fetch the NSDictionary as mutableCopy, work on that, put the end result into an NSDictionary and reinsert that into the managedObject. Did the trick for me and i havent found another solution yet.

Luc Bernardin