Modified to answer concerns appearing in comments.
Have the following code:
import SwiftUI
import SwiftData
@main
struct Fu: App {
var body: some Scene {
WindowGroup {
ContentView()
}
//.modelContainer(for: Bar.self)
}
}
@Model
class Bar{
var a: String
var b: String
init(a: String = "", b: String = "") {
self.a = a
self.b = b
}
}
struct ContentView: View {
//@Environment(\.modelContext) var modelContext
//@Query var fu: Bar
var fu = Bar()
var body: some View {
NavigationStack {
if (fu.a.isEmpty) {
NavigationLink("Lucy! I'm home.") {
StartScreen()
}
} else {
Text("whatever")
}
}
}
}
struct StartScreen: View {
var body: some View {
Text("Hello, World!")
}
}
The above compiles and runs. In "ContentView," uncomment the '@Query...' and comment 'var fu = ....' on the next line. The editor shows no error. Now click 'run.' The build fails, but no indicataion in the editor. The issues frame shows 'Element is not a member type of class 'example.Bar' - click on the message and the 'private(set)' line appears beneath the @Query.
@Querygives you an array containing all theBars in the model container. Which one do you want to be edited by the text field?private(set) var _fu: SwiftData.Query<Bar.Element, Bar> = .init(). If you have no idea what that line means, why is it there?