はじめに
昨日に引き続き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
を使わずとも複数の値を監視できるなんて、、、
参考記事