且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在核心数据中更新对象值也将创建一个新对象

更新时间:2023-11-30 14:20:46

问题代码中没有任何操作创建新的托管对象,因此,问题出在代码的其他地方,或者您误认为正在创建一个额外的对象-您不会说得出这个结论的方式。

Nothing in the code in your question is creating a new managed object, so either the problem is elsewhere in your code or you're mistaken that an extra object is being created - you don't say how you have come to this conclusion.

要确定问题所在,请在 NewLog 上实现 awakeFromInsert >对象并添加一个断点。每次添加这些对象之一时都会被点击,然后您可以检查堆栈跟踪以找出从何处添加对象。

To identify the problem, implement awakeFromInsert on your NewLog object and add a breakpoint. This will be hit every time one of these objects is added, you can then examine the stack trace to find out where the object is being added from.

更新

好的,完成后,您会看到每次执行Segue时都要创建一个新实体。不要那样做您需要执行访存来找到现有的登录对象,并且仅当没有一个登录对象或现有的登录对象不合适时,才创建一个新的登录对象。

OK, having done that, you see that you're making a new entity every time the segue is performed. Don't do that. You need to perform a fetch to find the existing login object, and only if there isn't one, or the existing one isn't suitable, create a new one.

如果进行访存且数组中没有任何内容,则 objectAtIndex:0 将崩溃。使用 firstObject 代替,并检查结果是否为零。

If you do a fetch and there's nothing in the array, objectAtIndex:0 will crash. Use firstObject instead and check if the result of that is nil.