class Form {
var id = UUID()
var name: String = ""
var fields: [FormField] = []
}
class FormField {
var id = UUID()
var name: String = ""
}
struct LogCustomizationView: View {
@State var form: Form
var body: some View {
VStack {
ForEach(form.fields.indices) { idx in
TextField("Name", text: self.$form.fields[dynamicMember: idx])
}
}
}
}
The problematic line is:
TextField("Name", text: self.$form.fields[dynamicMember: idx])
The first error I got was
Missing argument label 'dynamicMember:' in subscript
So I added dynamicMember:, which is how it's shown above. Now the error I get is:
Cannot convert value of type 'Int' to expected argument type 'WritableKeyPath<_, _>'