获取对象时 CoreStore Xcode 数据错误问题
CoreStore Xcode data fault issue when fetching objects
我是 CoreStore 的新手,正在尝试测试我正确创建、存储和获取 CoreStore 对象的能力。条目似乎是根据 dataStack.fetchCount() 和 transaction.create() 的结果创建的,但是根据我的 dataStack.fetchAll() 结果,数据不可用或存储不正确(它说data: fault 在每个对象的末尾)和使用 Liya 软件检查 SQLite 数据库发现 table 中没有条目。我使用的是 CoreStore v8.0.1 和 Xcode v12.4。我的示例代码(使用同步执行)如下。感谢您对解决问题的投入。谢谢
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()
}
}
}
感谢您的帮助。
原来在访问对象的属性之前,fetch结果会显示data:fault。以下示例代码将显示属性的值:
let objects = try dataStack.fetchAll(From<MyImage>())
print(objects.map { [=10=].desc })
我是 CoreStore 的新手,正在尝试测试我正确创建、存储和获取 CoreStore 对象的能力。条目似乎是根据 dataStack.fetchCount() 和 transaction.create() 的结果创建的,但是根据我的 dataStack.fetchAll() 结果,数据不可用或存储不正确(它说data: fault 在每个对象的末尾)和使用 Liya 软件检查 SQLite 数据库发现 table 中没有条目。我使用的是 CoreStore v8.0.1 和 Xcode v12.4。我的示例代码(使用同步执行)如下。感谢您对解决问题的投入。谢谢
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()
}
}
}
感谢您的帮助。
原来在访问对象的属性之前,fetch结果会显示data:fault。以下示例代码将显示属性的值:
let objects = try dataStack.fetchAll(From<MyImage>())
print(objects.map { [=10=].desc })