1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| // 扱いたいModelを指定してContainerを生成する
// Initialize with only a schema
let container = try ModelContainer([Trip.self, LivingAccommodation.self])
// containerの生成例 (option指定あり)
// Initialize with configurations
let container = try ModelContainer(
for: [Trip.self, LivingAccommodation.self],
configurations: ModelConfiguration(url: URL("path"))
)
// SwiftUIでcontainerを使う場合はmodifierを使う
import SwiftUI
@main
struct TripsApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(
for: [Trip.self, LivingAccommodation.self]
)
}
}
|