New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' crash when deleting non-persisted Core Data entities #31
Comments
The normal way to use TLIPT with Core Data is:
Can you do that? |
Wowie. In short, yes, I could. If in the eyes of TLIPT what I've done is somehow really stupid (which I don't think is, given that The surprising crash behaviour is also seen in #22 — may be the thing that's more effective than investing any to fix the issue is just to provide more useful error messages. I see TLIPT as a dependable component that connects data to my UI, and so to get crashes from it is really unsettling. When it works though it works beautifully, so thanks for that. =] If only I had the time to delve into TLIPT's internals and philosophy + a workflow for submitting patches (from Cocoapods it's not trivial) I'd love to contribute back. For now I'm satisfied with the workaround. That's not to say this issue doesn't need addressing! |
TLIPT provides multiple ways to identify objects. From the API documentation:
The default behavior works in for the most common cases, but ultimately, the onus is on you to select an appropriate identifier. If you choose to use I'm not sure there's an issue to fix here other than touching up the documentation. |
The point is, TLIPT shouldn't crash and burn if those conditions are not satisfied. A more helpful error, rather than documentation, is the fix. i.e. with respect I don't think leaving codepaths to error states in the form of #22 is related — the difference there is that it's not a crash that happens in TLIPT, but an eventual consistency problem in CollectionView (just as ugly, really). For this one, onus may be on the user to select the correct identifier but I think you'll agree it's the onus of TLIPT not do throw NSArray index out of bounds exceptions under any circumstances. That's the responsibility of |
Synopsis
TPIPT's
[updates performBatchUpdatesOnCollectionView:self.collectionView];
crashes because it's confused whenever unpersisted Core Data entities that use a specificidentifierKeyPath
gets deleted.Reproduction
Have a view controller hooked up with a collection view, and implement the delegate methods as TLIPT intends.
MR_createEntity
. Do not save the entity.MR_deleteEntity
(this essentially calls[context deleteObject:inContext];
behind the scenes. This is bog standard Core Data).The Crash
The error is uninformative and leaves me with no leads. Perhaps TLIPT can improve on these error messages to help the user get back on their feet.
Offending code
The crash can be traced down into the code below in
TLIndexPathUpdates.m
:Extra information
I've defined my indexPathController like so:
This function is pretty unsafe, because it's making the assumption that
self.oldDataModel indexPathForItem
will always succeed.Below is some useful trace info I gathered when investigating the problem.
It's obvious that in the old model, there's one item that has a data fault. This would cause
[self.oldDataModel indexPathForItem:item];
to returnnil
, because it cannot access the identifier fieldsomeID
of the deleted object, and therefore cannot look up the correctindexPath
and therefore returnsnil
. This crashes the app.Workaround
Persist the object (this is not what I want to do every time I create an object!)
The text was updated successfully, but these errors were encountered: