I am facing issues setting up Binding in the following SwiftUI code snippet. I am trying this on xCode Beta 7 ((11M392r).
In the code snippet below, I am creating 2 Stepper views.
If I pass $student.totalMarks to Stepper, it works and creates the right Binding.
But if I try to access $student.marks.score1, that does not work and shows the following compilation error:
Generic parameter 'Subject' could not be inferred.
Is there a way to pass single field from a nested property into a binding?
struct Marks {
public let score1: Int
public let score2: Int
public let score3: Int
}
class Student: ObservableObject {
@Published var totalMarks: Int = 145
@Published var marks = Marks(score1: 67, score2: 56, score3: 64)
}
struct ContentView: View {
@ObservedObject var student = Student()
var body: some View {
return VStack {
Stepper("Total Score: \(student.totalMarks)", value: $student.totalMarks)
Stepper("Score 1: \(student.marks.score1)", value: $student.marks.score1)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}