Evgeniy Kleban
Evgeniy Kleban

Reputation: 6975

MagicalRecord not saving

I wonder why my Core Data stop to save changes. In fact, code above worked hours ago. When i try to print out an error, it print (null). Code below is custom method for NSManagedObjectSubclass:

-(void)bindWithModel:(MenuAPIModel*)model{

    self.basketId = [model.basketId integerValue];
    self.coreId = [model.itemId integerValue];
    self.name = [model name];
    self.orderId = [model.orderId integerValue];
    self.payedFrom = [model payedFrom];
    self.persons = [model persons];
    self.price = [model.price integerValue];
    self.price3 = [model.price3 integerValue];
    self.price12 = [model.price12 integerValue];
    self.status = [model status];

     [[NSManagedObjectContext MR_defaultContext] MR_saveOnlySelfWithCompletion:^(BOOL contextDidSave, NSError * _Nullable error) {

    NSLog(@"error %@", error.localizedDescription);

}];

Error is null and contextDidSave is YES. But when i try to access entity it prints null, and SQL table is an empty. Why?

Upvotes: 0

Views: 141

Answers (1)

Mateusz
Mateusz

Reputation: 1224

I assume that bindWithModel method is in NSManagedObject subclass. If so, then you should use managedObjectContext property from this class rather then MR_defaultContext:

[self.managedObjectContext  MR_saveOnlySelfWithCompletion:^(BOOL contextDidSave, NSError * _Nullable error) { (...) }];

Previously it was working probably because context from [NSManagedObjectContext MR_defaultContext] was the same as self.managedObjectContext.

Upvotes: 1

Related Questions