NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

Text field binding to structured array

Forums > SwiftUI



I have a structure in my code which defines some variables for players of the app.

After adding the structure and a first set of test values for the name of the player i want the player to be able to change their name inside of a text field.

I have defined the Array inside the View body but somehow when I write this line of code for the textfield:

TextField("Player 1", text: $ [playeramount])

the following error shows up:

Value of type 'Binding <[PlayerModel]>' has no dynamic member 'name' using key path from root type ' [PlayerModel]'

Thanks for your help!!

I'm just starting to learn xcode, so excuse me if the question may be easy...


Could you show the code for the struct defintion, and how you define player?

Just reading the error message, can I ask if name is and element in the struct you have defined?


Hacking with Swift is sponsored by Instabug

SPONSORED Catch bugs as soon as they happen and know exactly why a crash occurred. Instabug's SDK grabs all the logs they need to fix bugs, crashes and performance issues in minutes instead of days. Get screenshots, device details, network logs, repro steps, and tons of other critical insights needed to resolve issues and prioritize product backlogs straight from your dashboard. It only takes a minute to integrate!

Get started now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.