NSValueTransformer + MagicalRecord + Mogenerator

87 Views Asked by At

I can't get my NSValueTransformer implementation to get called upon calling save:(NSErrro **) on my ManagedObjectContext.

I've already tried to fix this problem by wring my own ManagedObject-Class and not relying on Mogenerator, without any success.

Here is a screenshot of my entity configuration: enter image description here

Here is my NSValueTransformer-Subclass (non of the breakpoints will be hit): enter image description here

And here is how i create the model and save the context. I've also tried to use the MR_create and MR_saveToPersistentStoreCoordinator-Methodes for crating and saving but without any success.

enter image description here

Why does core data not execute my NSValueTransformer code when saving the entity to the persistent store coordinator?

1

There are 1 best solutions below

0
Sascha Held On

Turns out that it's super important that the NSManagedObjectContext is directly connected to the NSPersistentStoreCoordinator. There seems to be a difference between using [NSMangedObjectContext MR_default] and the following expression:

NSPersistentStoreCoordinator *coordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];
NSManagedObjectContext *context = [NSManagedObjectContext MR_contextWithStoreCoordinator:coordinator];

I've modified the above code so it uses the other NSManagedObjectContext, now my NSValueTransformer will be hit.

Session *session = [self getSession];
[session MR_deleteEntityInContext:context];

session = [Session sessionWithFirstName:firstName surname:surname response:jsonResponse andContext:context];
[context MR_saveToPersistentStoreWithCompletion:nil];

So my problem is solved - in case somebody knows why I can't use [NSManagedObjectContext MR_default] I would be very interested!