Home > Mobile >  Check Number of Characters Of Textfield in SwiftUI
Check Number of Characters Of Textfield in SwiftUI

Time:06-15

I am new to SwiftUI and I need to call a function when user enters minimum three characters in a textfield.

Like this:

simulator

After completing three or more characters I want to perform a function. Is there any way to do this in SwiftUI?

CodePudding user response:

You can use .onChange :

.onChange(of: name) { newValue in
                    
                    if newValue.count >= 3 {
                        // Call function
                    }
}
  • Related