I would like to get the string entered in the TextEditor of SwiftUI and store it in an array. How should I append to textdata?
struct TextEditorTest: View {
@State var textdata: [String] = []
@State var text1: String = ""
var body: some View {
TextEditor (text: $text1)
}
}
CodePudding user response:
@State var textdata: [String] = []
@State var text1: String = ""
var body: some View {
TextEditor (text: $text1)
.onChange(of: text1) { newValue in
print(newValue)
//perform your logic here because it will trigger as soon as value is changed in field
}
}