LoginSignup
2
1

More than 3 years have passed since last update.

【SwiftUI】TextFieldに初期値を入れる

Last updated at Posted at 2020-02-23

initではなくて.onAppearで初期値を代入する

struct ContentView: View {
    @State var text:String = ""

    var body: some View {
        TextField("", text: $text)
        .onAppear {
            // ここで初期値を代入
            self.text = "default text"
        }
    }
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1