core-data icon indicating copy to clipboard operation
core-data copied to clipboard

fatalError("Returned multiple objects, expected max 1")

Open beefroast opened this issue 6 years ago • 3 comments

What is the point of this? Why set the fetchLimit to 2 and then fatal error if two objects are returned?

beefroast avatar Jan 12 '20 23:01 beefroast

The point is to assert an assumption.

You are right, that you could just limit your query result, but that would potentially mask a serious problem. So this is a pretty good safeguard to have.

tkrajacic avatar Jan 13 '20 09:01 tkrajacic

So why not use assert, or just throw an error so that the calling function can choose to crash if it's appropriate?

beefroast avatar Jan 13 '20 22:01 beefroast

Well, how would you recover from this error? This is really an error in the programmer's logic if this happens, so not recoverable at runtime really. You are of course free to change the logic yourself, if you think this can be handled differently. Nothing wrong with that.

tkrajacic avatar Jan 14 '20 10:01 tkrajacic