Hi, I have the following setup in SwiftUI:
struct SetGroupView: View {
@Bindable var setGroup: ExerciseSetGroup
var body: some View {
List {
ForEach(setGroup.sets!) { set in
SetRowView(set: set)
}
}
}
}
struct SetRowView: View {
@Bindable var set: ExerciseSet
var body: some View {
TextField("0", value: $set.weight, format: .number)
}
}
ExerciseSetGroup
and ExerciseSet
are @Model
objects which I am using with SwiftData. The problem is that any kind of editing within the textfield is very laggy, which I assume is caused by binding the value to the model itself. I have tested various approaches, including adding @State
properties to the SetRowView
to bind to the textfield instead. However, in this approach I need to manually update the SwiftData model, which again leads to lag when scrolling the list. My question is, is this performance issue something that just happens with SwiftData and is there any way to avoid it / fix it? The code I have given is simplified, but I debugged my code and pinpointed the performance issue down to this setup. I would appreciate any help, thanks.