mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
Crash with implicitly unwrapped optional on a simple setup #46
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rshev on GitHub (Apr 13, 2016).
I'm getting
fatal error: unexpectedly found nil while unwrapping an Optional valueonfetchAllin the following simple setup:Crash occurs in
entityNameForClassfunc, and entityUserclearly exists in the model.What am I doing wrong?
PS. Maybe you shouldn't implicitly unwrap optional there at all? What if someone feeds wrong class?
@JohnEstropia commented on GitHub (Apr 14, 2016):
@rshev Did you check if the
Userclass is set correctly in your xcdatamodeld file? Note that theModulename matters.You can inspect how your entities look like after calling
addSQLiteStoreAndWait():Nobody should be able to perform operations on a wrong class (i.e. you shouldn't be fetching/creating a class that's not in your model), so catching this mistake early is best.
See the README file's entry on Creating Objects (yours is a fetch, but the same principles apply):