TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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 RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.