Is there any text controls event in Swift ui

as for textfield in storyboard, there are many event we can use,
like
Edit changed,
Edit Did End… etc

I am wondering for text in swiftui, is there any similiar event, text control can trigger?

Most likely your TextField is bound to a state property, in that case you can use Swift’s property observers (didChange/willChange).

Yes there is: onEditingChanged and onCommit
https://developer.apple.com/documentation/swiftui/textfield/3338360-init

I think they are respectively for when the text field obtain or loses the focus, and when a commit action is done (such as tapping the return key on the soft keyboard). In both cases, these events happen before or after editing the text, but they are not called while editing.

1 Like