You have two problems in your code. First, the @State property wrapper is for structs, not classes. You need to use the @StateObject property wrapper for classes. Either use @StateObject in the view or make QuizPlayer a struct instead of a class and remove @Published from the QuizPlayer fields.
Second, you are overcomplicating things with binding a player's name to a text field. Instead of accessing the players using an index, go through the array of players and bind each player's name to the text field. The code will look similar to the following:
ForEach(quizPlayers, id:\.self) { $player in
TextField("Player Name: ", text: $player.name)
}
The $player argument gives you the current player so you do not have to access the quizPlayers array or deal with array indexes.
Keep in mind I typed the code from memory so I cannot guarantee it will work correctly if you copy and paste it in your code. You may need to change $player to player. But the code gives you an idea of what you need to do to bind the player's name to the text field.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: