CoreStore Xcode data fault issue when fetching objects

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: fault at the end of each object) and inspection of the SQLite database with Liya software reveals no entries in the table. I'm using CoreStore v8.0.1 and Xcode v12.4. My example code (using synchronous execution) is below. I appreciate your input into troubleshooting the issue. Thanks.

MyImage.swift:

import CoreStore
final class MyImage: CoreStoreObject {
    @Field.Stored("desc")
    var desc: String = ""
}

MyApp.swift

import SwiftUI
import CoreStore
import Foundation

@main
struct MyApp: App {
    
    static let dataStack: DataStack = {
        let dataStack = DataStack(
            CoreStoreSchema(
                modelVersion: "V1",
                entities: [
                    Entity<MyImage>("MyImage")
                ],
                versionLock: [
                    "MyImage": [..., ..., ..., ...]
                ]
            )
        )
        
        try! dataStack.addStorageAndWait(
            SQLiteStore( fileName: "MyStore.sqlite",
                //localStorageOptions: .allowSynchronousLightweightMigration,
                localStorageOptions: .recreateStoreOnModelMismatch
            )
        )
        print(dataStack.coreStoreDumpString)
        return dataStack
    }()
    
    init() {
        CoreStoreDefaults.dataStack = MyApp.dataStack
        try! dataStack.perform(
            synchronous: { (transaction) in
                let test_obj = transaction.create(Into<MyImage>())
                test_obj.desc = "Description"
            },
            waitForAllObservers: true
        )
        
        do {
            let objects = try dataStack.fetchAll(From<MyImage>())
            print(objects)
        } catch { print("error fetching")}
    }
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

I appreciate your help.



Read more here: https://stackoverflow.com/questions/68463258/corestore-xcode-data-fault-issue-when-fetching-objects

Content Attribution

This content was originally published by euro_passion_2005 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: