xcode Core Data Annotation - 修复缺失的删除传播
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14823762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Core Data Annotation - Repairing Missing Delete Propagation
提问by user2006934
I have a program that works perfectly fine. No crash, no bug or anything, but when it comes to deleting an NSManagedObject, the following message appears in the console.
我有一个运行良好的程序。没有崩溃,没有错误或任何东西,但是在删除 NSManagedObject 时,控制台中会出现以下消息。
Core Data: annotation: repairing missing delete propagation for to-one relationship
And then, some details about the relationship.
然后,关于关系的一些细节。
Once again, this does not make the app crash and the program goes on running as expected, but still, that makes me worried. Should I do something about it or is it alright to have some annotations from Core Data?
再一次,这不会使应用程序崩溃,程序会按预期继续运行,但这仍然让我担心。我应该对此做些什么还是可以从 Core Data 中获得一些注释?
Thanks in advance :)
提前致谢 :)
回答by dulgan
You should adopt a better strategy on deletion.
您应该采用更好的删除策略。
- Go to your .xcdatamodeld, select the concerned relationship
- Select your entity and relationship using an inverse relation
Choose what to do on Delete Rule
- 转到您的 .xcdatamodeld,选择相关关系
- 使用逆关系选择您的实体和关系
选择要对删除规则执行的操作
回答by ak_
You must save context after deleting a managed object.
删除受管对象后必须保存上下文。
After deleting something:
删除东西后:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSError *error;
if (![appDelegate.managedObjectContext save:&error]) {
NSLog(@"Error in Appdelegate>getLocalVersionAddFirstVersion");
}
Just as a new object is not saved to the store until the context is saved, a deleted object is not removed from the store until the context is saved. (Apple Documentation)
正如在保存上下文之前不会将新对象保存到商店一样,在保存上下文之前不会从商店中删除已删除的对象。(苹果文档)
回答by MartinW
I had the same problem and it went away, as soon as i added an inverse relationshipfor the relationship in question.
我遇到了同样的问题,只要我为相关关系添加了逆关系,它就消失了。
回答by TheEye
For me it was a slightly different problem: there was an orphan detectionin place that removed the newly created object right away when it was saved, because I forgot to add the new parent relationship to the isOrphan()
function. Strangely enough it lead to exactly this error ...
对我来说,这是一个稍微不同的问题:有一个孤儿检测,在保存新创建的对象时立即删除它,因为我忘记向isOrphan()
函数添加新的父关系。奇怪的是,它导致了这个错误......