简体   繁体   English

核心数据注释 - 修复丢失的删除传播

[英]Core Data Annotation - Repairing Missing Delete Propagation

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 :) 提前致谢 :)

You should adopt a better strategy on deletion. 你应该采取更好的删除策略。

  1. Go to your .xcdatamodeld, select the concerned relationship 转到.xcdatamodeld,选择相关关系
  2. Select your entity and relationship using an inverse relation 使用反向关系选择您的实体和关系
  3. Choose what to do on Delete Rule 选择删除规则要执行的操作

    在此输入图像描述

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 ) Apple文档

我有同样的问题,一旦我为相关关系添加了反比关系 ,它就消失了。

For me it was a slightly different problem: there was an orphan detection in 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. 对我来说这是一个稍微不同的问题:有一个孤立检测到位,在保存时立即删除了新创建的对象,因为我忘了将新的父关系添加到isOrphan()函数中。 Strangely enough it lead to exactly this error ... 奇怪的是,这导致了这个错误......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM