I would like to learn the best practice of supporting SwiftData in an app running on minimum iOS16.
The basic main app code:
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
I have a basic Person class with name and email address properties. Since SwiftData is not supported on iOS 16, the below does not work:
import SwiftUI
import SwiftData
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(for: Person.self)
}
}
Using if #available(iOS 17, *)
is wrong because control flow statements cannot be used in a SceneBuilder.
How do I go about attaching a model container to the WindowGroup while maintaining support to iOS16 at the same time?