3
1

More than 1 year has passed since last update.

はじめに

昨日に引き続きonChangeに関する内容です。

実装

import SwiftUI

struct ContentView: View {
    @State private var text1 = ""
    @State private var text2 = ""
    var body: some View {
        VStack(spacing: 10) {
            TextField("", text: $text1, axis: .horizontal)
            
            TextField("", text: $text2, axis: .horizontal)
        }
        .onChange(of: [text1, text2]) { newValue in
            print("text1:", newValue[0])
            print("text2:", newValue[1])
        }
    }
}

おわり

CombineのcombineLatestを使わずとも複数の値を監視できるなんて、、、

参考記事

3
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
3
1