GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

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 try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket 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.