UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: TextField - how to provide an initial value

Forums > SwiftUI

I'm working on an app that has a Tournament struct and an [Tournament]. The struct will contain Strings, a Date, some Ints, etc.

On the first screen, the app will show a list of Tournaments and an "Add a new Tournament" Button.

Pressing the Button will navigate to a screen with Labels and TextFields for the user to fill in.

Pressing on an item in the list of Tournaments should show the same screen, but with the previously defined elements already filled in.

I've been searching, but clearly I haven't figured out the correct search terms, because I can't find how to do this in SwiftUI. I feel like it was pretty straightforward in UIKit.....

Any ideas?

3      

hi

you just initialise the State which your textfields are bound to in a custom init or in .OnAppear

take a look at this:

https://stackoverflow.com/questions/56691630/swiftui-state-var-initialization-issue

rich

3      

Thanks! I knew it should be easy. I don't know why I struggled to find the answer myself.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.