I am trying to implement a simple Table with a TextField that makes it possible to edit the data.
Below is a very simple example where I am trying to do this. It works, but it becomes very unresponsive as the number of people increases.
The example as it is, has 1,000 people. It is very slow when a TextField gets focus and is used to edit something. Strangely, it also gets very slow when you scroll through an entry that has been edited. It crashes completely when 10,000 people is used.
I found this similar question on the web, but it is not answered.
What should I do to implement an editable Table like this?
struct ContentView: View {
struct Person: Identifiable {
var givenName: String
var familyName: String
let id = UUID()
}
@State private var people = [Person].init(repeating: Person(givenName: "Name", familyName: "Family"), count: 1000)
var body: some View {
Table($people) {
TableColumn("Given Name") { $person in TextField("Name", text: $person.givenName) }
TableColumn("Family Name") { $person in TextField("Family Name", text: $person.familyName) }
TableColumn("Full Name") { $person in Text("\(person.givenName) \(person.familyName)")}
}
}
}