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?
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.