@joadan yes, the application crashes as well.
The below view will terminated the app if you attempt to save a local item.
struct ContentView: View {
@State private var localId: Int = 0
@State private var localCount: Int = 0
@State private var remoteId: Int = 0
@State private var remoteCount: Int = 0
private var localContainer: ModelContainer
private var remoteContainer: ModelContainer
private let log = Logger()
init() {
localContainer = {
do {
let schema = Schema(versionedSchema: LocalSchema.self)
let config = ModelConfiguration("local", schema: schema, isStoredInMemoryOnly: true, allowsSave: true, cloudKitDatabase: .none)
return try ModelContainer(for: schema, configurations: config)
}
catch {
fatalError("could not create local store")
}
}()
remoteContainer = {
do {
let schema = Schema(versionedSchema: RemoteSchema.self)
let config = ModelConfiguration("remote", schema: schema, isStoredInMemoryOnly: true, allowsSave: true, cloudKitDatabase: .none)
return try ModelContainer(for: schema, configurations: config)
}
catch {
fatalError("could not create remote store")
}
}()
}
var body: some View {
HStack {
VStack {
Text("\(localCount)")
Button("Save Local") {
do {
log.info("save local")
localId += 1
let context = ModelContext(localContainer)
let item = LocalSchema.Item(title: "local: \(localId)", created: .now, modified: .now)
context.insert(item)
try context.save()
localCount = try context.fetchCount(FetchDescriptor<LocalSchema.Item>())
} catch {
log.error("\(error.localizedDescription)")
}
}
}
VStack {
Text("\(remoteCount)")
Button("Save Remote") {
do {
log.info("save remote")
remoteId += 1
let context = ModelContext(remoteContainer)
let item = RemoteSchema.Item(title: "remote: \(remoteId)", created: .now, modified: .now, origin: "from space")
context.insert(item)
try context.save()
remoteCount = try context.fetchCount(FetchDescriptor<RemoteSchema.Item>())
} catch {
log.error("\(error.localizedDescription)")
}
}
}
}
}
}