Originally created by @rshev on GitHub (Apr 13, 2016).
I'm getting fatal error: unexpectedly found nil while unwrapping an Optional value on fetchAll in the following simple setup:
do {
try CoreStore.addSQLiteStoreAndWait()
let users = CoreStore.fetchAll(From(User))
print(users)
}
catch (let error) {
print(error)
}
Crash occurs in entityNameForClass func, and entity User clearly 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?
Originally created by @rshev on GitHub (Apr 13, 2016).
I'm getting `fatal error: unexpectedly found nil while unwrapping an Optional value` on `fetchAll` in the following simple setup:
```
do {
try CoreStore.addSQLiteStoreAndWait()
let users = CoreStore.fetchAll(From(User))
print(users)
}
catch (let error) {
print(error)
}
```
Crash occurs in `entityNameForClass` func, and entity `User` clearly 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?
adam
added the wontfix label 2025-12-29 15:22:56 +01:00
PS. Maybe you shouldn't implicitly unwrap optional there at all? What if someone feeds wrong class?
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):
If the entity does not belong to any store, an assert will be triggered. This is a programmer error and should never occur in production code.
@JohnEstropia commented on GitHub (Apr 14, 2016):
@rshev Did you check if the `User` class is set correctly in your xcdatamodeld file? Note that the `Module` name matters.
You can inspect how your entities look like after calling `addSQLiteStoreAndWait()`:
``` swift
try CoreStore.addSQLiteStoreAndWait()
print(CoreStore.entityTypesByName)
```
> PS. Maybe you shouldn't implicitly unwrap optional there at all? What if someone feeds wrong class?
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](https://github.com/JohnEstropia/CoreStore#creating-objects) (yours is a fetch, but the same principles apply):
```
If the entity does not belong to any store, an assert will be triggered. This is a programmer error and should never occur in production code.
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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):