核心数据:删除未保存的对象时出错

发布于 2024-09-11 10:18:32 字数 497 浏览 5 评论 0原文

我在核心数据项目上遇到了一些麻烦。我有一个 NSArrayController,其中包含 NSManagedObjects 和 + / - 按钮。如果我在保存文件后删除行中的一个对象,它可以正常工作,但是如果我添加一个新对象,然后立即再次删除它(不更改任何默认值),我会收到错误:

Serious application error.  Exception was caught during Core Data change processing: Unknown number type or nil passed to arithmetic function expression. with userInfo (null)  
Unknown number type or nil passed to arithmetic function expression.  

情况相同如果我撤消新对象的添加。

有人可以指点我该怎么做吗?我认为这与它只有一个临时 ID 有关,但我不知道如何解决。

I have some trouble with a core data project. I have a NSArrayController with NSManagedObjects in it, and + / - buttons. If i delete a object in the row after the file has been saved it works perfectly, but if I add a new object, and immediately delete it again (without changing any of the default values), i get an error:

Serious application error.  Exception was caught during Core Data change processing: Unknown number type or nil passed to arithmetic function expression. with userInfo (null)  
Unknown number type or nil passed to arithmetic function expression.  

It's the same case if i undo the add of the new object.

Anybody able to give me a pointer what to do? I assume it has something to do with that it only has an temporary ID, but how to solve it i don't know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遮云壑 2024-09-18 10:18:33

我找到了问题和解决方案。为了记录在案,我将描述它。

问题在于该对象在其 init 函数中添加了一个观察者。这可能是引发错误的原因。如果我在删除对象之前将其自身作为观察者删除,则不会产生错误。

I found the problem and solution. For the record i will describe it.

The problem was that the object in its init function added an observer on itself. This was probably what triggered the error. If i before i delete the object remove itself as observer, the error is not produced.

满天都是小星星 2024-09-18 10:18:33

表通常不包含 NSManagedObjects。相反,要么 NSArrayController 通过绑定提供托管对象的属性作为值,要么是符合 NSTableViewDataSource 的对象。可以通过多种方式来删除在这些场景中的任一个中提供的选定对象。问题是,你根本没有解释你的案件是如何建立的。

您的删除(无论您的按钮连接到什么目标/操作)是否可能被传递为零或出现意外情况?如果您要求托管对象上下文删除浮点值或其他一些随机的东西,我可以想象一个类似的可怕错误......

Tables don't usually contain NSManagedObjects. Rather, either an NSArrayController is providing the managed objects' attributes as values via bindings or an object conforming NSTableViewDataSource is. The deletion of a selected object provided in either of these scenarios can be done a myriad of ways. The problem is, you haven't explained at all how your case is set up.

Is it possible your deletion (whatever target/action your button is wired to) is being passed nil or something unexpected? I can imagine a similarly-frighenting error if you asked a managed object context to delete a float value or some other random thing ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文