I'm working on an exercise app and have been running into the error "Cannot assign to property: "weightArray" is a get-only property".
I want to have the textfield be able to enter a different numerical value for each set (0..<4)
I believe I need to use { get set }
in weightArray
in my model data but I can't seem to figure out exactly how to implement it.
View:
@Binding var data: Exercise
var body: some View {
List {
VStack(alignment: .leading) {
ForEach(0..<4, id: \.self) { sets in
ZStack {
RoundedRectangle(cornerRadius: 8)
.fill(.opacity(0.1))
TextField("0", text: $data.weightArray[sets])
.multilineTextAlignment(.center)
.keyboardType(.decimalPad)
}
.frame(width: 65, height: 30)
Text("lbs")
Divider()
}
}
}
}
}
Model:
struct Exercise: Identifiable, Codable {
let id: UUID
var weight: [String]
var weightArray: [String] {
let array: Array<String> = Array(repeating: "0", count: numericalSets)
return array
}
Any help is appreciated.