😩 Editor → Canvas → Automatically Refresh Canvas OFF
You can turn off the auto-compile feature for previews/canvas'. When having a SwiftUI View open in the editor go to the Editor -> Canvas -> Automatically Refresh Canvas.
$ sqlite default.store
SQLite version 3.43.2 2023-10-10 13:08:14
Enter ".help" for usage hints.
sqlite> .tables
ACHANGE ATRANSACTIONSTRING ZTODO Z_MODELCACHE
ATRANSACTION Z_METADATA Z_PRIMARYKEY
sqlite> .schema ZTODO
CREATE TABLE ZTODO ( Z_PK INTEGER PRIMARY KEY, Z_ENT INTEGER, Z_OPT INTEGER, ZTIME TIMESTAMP, ZTEXT VARCHAR );
sqlite> .headers on
sqlite> .mode column
sqlite> select * from ZTODO;
Z_PK Z_ENT Z_OPT ZTIME ZTEXT
---- ----- ----- ---------------- -----------------------------------------------------------
11 2 1 727759392.308872 2. Do, or do not. There is no try.
12 2 1 727759392.914907 3. Most things look better when you put them in a circle.
13 2 1 727759393.191901 4. Could not get advice.
14 2 1 727760485.069984 0. You're not that important; it's what you do that counts.
15 2 1 727760485.781123 1. Most things done in secrecy are better left undone.
16 2 1 727760486.503812 2. When in doubt, just take the next small step.
17 2 1 727760487.112024 3. Have a firm handshake.
SwiftData/ModelContainer.swift:159: Fatal error: failed to find a currently active container for Task
Failed to find any currently loaded container for Task)
コンテナを渡す前に初期化すると問題が解決されるようです。
@main
struct MyApp: App {
let modelContainer: ModelContainer
init() {
do {
modelContainer = try ModelContainer(for: Item.self)
} catch {
fatalError("Could not initialize ModelContainer")
}
}
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(modelContainer)
}
}
struct ContentView: View {
@State private var container = ModelContainer(...)
var body: some Scene {
RecipesList()
.modelContainer(container)
}
}
それ以下では @Environmentを使って問題なく利用できると思っていましたが。
struct RecipesList: View {
@Environment(\.modelContext) private var modelContext
The environment’s modelContext property will be assigned a new context associated with this container. All implicit model context operations in this view, such as Query properties, will use the environment’s context.