Jonas Jongejan
Jonas Jongejan

Reputation: 3146

Core Data: Error if deleting unsaved object

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.

Upvotes: 0

Views: 561

Answers (2)

Jonas Jongejan
Jonas Jongejan

Reputation: 3146

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.

Upvotes: 1

Joshua Nozzi
Joshua Nozzi

Reputation: 61248

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 ...

Upvotes: 0

Related Questions