mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
CoreStore object data are not being stored correctly... #369
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 @bradleydworak on GitHub (Jul 12, 2021).
Hi,
I'm new to CoreStore and attempting to test my ability to create, store, and fetch CoreStore Objects correctly. It appears entries are being created based on results of dataStack.fetchCount() and transaction.create(), but the data is unavailable or not stored correctly based on my results of dataStack.fetchAll() (it says data: at the end of each object) and inspection of the SQLite database with Liya software reveals no entries in the table. My example code is as follows:
MyImage.swift:
ContentView.swift:
I appreciate your help. Thanks, Brad
@JohnEstropia commented on GitHub (Jul 13, 2021):
@bradleydworak You are accessing
dataStack.perform(...)before yourdataStack.addStorage(...)has completed. You will need to handle this timing by yourself (ex: CreateContentViewonly after thecompleted:closure has executed)@bradleydworak commented on GitHub (Jul 14, 2021):
Thanks @JohnEstropia for your guidance. I order to ensure
dataStack.addStorage(...)has completed before theContentView()has been created, my strategy is to move thelet dataStack: DataStack = {...}()code into the Swift file containing @main precedingContentView(). If this makes sense, then what additional code needs to placed here in order to calldataStack.addStorage(...)first? My example code is as follows:MyApp.swift
I appreciate your help. Thanks again, Brad
@bradleydworak commented on GitHub (Jul 20, 2021):
Hi @JohnEstropia, I modified my example code as a sanity check to ensure I can add the storage, create a object, and fetch objects synchronously in the
init()section before I callContentView(). I'm still getting the same error in which I notice the words data: fault for each of the entities listed fromfetchAll(), as well as no objects appear upon inspection of the database. I appreciate any information as to how I can troubleshoot this. My example code is as follows:MyApp.swift
I appreciate your help. Thanks again, Brad
@bradleydworak commented on GitHub (Jul 21, 2021):
I posted the issue on Stack Overflow as well:
https://stackoverflow.com/questions/68463258/corestore-xcode-data-fault-issue-when-fetching-objects
@JohnEstropia commented on GitHub (Jul 21, 2021):
@bradleydworak
These are your objects.
print()will only showfaultfor each object until you access any of their properties. TryI'm not sure how you inspect your DB, but if
dataStack.fetchAll()returns the correctcountof objects, that means the data do exist in the database. It's possible there are sync timing issues in the DB introspection method you use.@bradleydworak commented on GitHub (Jul 21, 2021):
Thanks @JohnEstropia for your input, much appreciated.
print(objects.map {$0.desc})indeed displays the value of the property for all entries. I use Liya software to inspect the SQLite database. It also is working now as the updates are displayed immediately after re-querying the database.