mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
fetchAll returning empty array #383
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 @darrenasaro on GitHub (Mar 17, 2022).
I have an app which stores an entity
class EntityA: NSManagedObject {...}I have the following simplified CoreData code to fetch this entity
I created the equivalent CoreStore code
The CoreData code returns the properly populated array while CoreStore returns an empty array. I tried initializing
SQLiteStorewith a number of different options, and tried the async versions ofaddStorageall to no avail. I set breakpoints in the relevant CoreStore functions, but could not find anything glaring that would indicate the issue. Not sure if this is a bug or if I am misusing CoreStore but any help here would be much appreciated.@JohnEstropia commented on GitHub (Mar 17, 2022):
@darrenasaro Since you're not getting an error at
try! dataStack.fetchAll(), then it's likely your SQLite file does not contain records in the first place.@darrenasaro commented on GitHub (Mar 17, 2022):
It does as evidenced by the CoreData implementation returning a populated array. I've swapped these implementations verbatim with all else equal and the CoreData one always returns a populated array while the CoreStore implementation always returns empty.
@JohnEstropia commented on GitHub (Mar 17, 2022):
@darrenasaro Can you print the original file URL from here
and check if it's still the same URL passed to
SQLiteStorehere?@darrenasaro commented on GitHub (Mar 17, 2022):
@JohnEstropia They are the same. I've recreated the issue in it's simplest form here
https://github.com/darrenasaro/fetch-demo
@JohnEstropia commented on GitHub (Mar 18, 2022):
Thanks for isolating the issue! I'll investigate
@JohnEstropia commented on GitHub (Mar 18, 2022):
@darrenasaro Oh boy... It looks like
NSPersistentContainerforces the file directory to where it likes. Try this out:Look at the output:
Note that
NSPersistentContainermoved the directory toLibrary/Application Support/, whileCoreStorekeeps it to where it's actually configured (/Documents/).@JohnEstropia commented on GitHub (Mar 18, 2022):
It looks like the behavior is correct if you use the

NSPersistentStoreDescriptionmethod instead:@JohnEstropia commented on GitHub (Mar 18, 2022):
Since it looks like CoreStore is behaving correctly here, I'm marking this issue as a
ios/compiler bug. I suggest that you find the original path actually created by theNSPersistentContainerfor your store, and then pass it to CoreStore in your migrated code. I'd also recommend submitting a bug report to Apple through feedback assistant, since this issue seems destructive enough on its own.@darrenasaro commented on GitHub (Mar 18, 2022):
@JohnEstropia Thank you for investigating this! Excited I can use this library now. This CoreData behavior definitely seems to be problematic. I actually downloaded the container to investigate and it looks like CoreData puts an sqlite file in
/Documents/(or whatever directory you specify) andLibrary/Application Support/, the former file having just structure data and the latter containing structure data as well as actual records. Super weird. Will follow with a bug report.@JohnEstropia commented on GitHub (Mar 18, 2022):
Oh my, that's even worse. I'll try to explain that situation in the CoreStore README for future migrators. Thanks for investigating the behavior further