gpt4 book ai didi

ios - MagicalRecord 不保存

转载 作者:行者123 更新时间:2023-11-29 00:32:05 25 4
gpt4 key购买 nike

我想知道为什么我的核心数据停止保存更改。事实上,上面的代码几小时前就可以工作了。当我尝试打印出错误时,它打印出 (null)。下面的代码是 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);

}];

错误为空,contextDidSave 为 YES。但是,当我尝试访问实体时,它会打印 null,并且 SQL 表为空。为什么?

最佳答案

我假设 bindWithModel 方法在 NSManagedObject 子类中。如果是这样,那么您应该使用此类中的 managedObjectContext 属性,而不是 MR_defaultContext:

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

以前它可以工作可能是因为 [NSManagedObjectContext MR_defaultContext] 的上下文与 self.managedObjectContext 相同。

关于ios - MagicalRecord 不保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41496514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com