textfield text change swift code example
Example 1: textchange in textview swift
class ViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var bodyText: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
bodyText.delegate = self
}
func textViewDidChange(_ textView: UITextView) {
print(textView.text);
}
}
Example 2: how to know when text changed textfield swiftui
import Combine
import SwiftUI
struct ContentView: View {
@State var location: String = ""
var body: some View {
TextField("Search Location", text: $location)
.onReceive(Just(location)) { location in
}
}
}