You might think it just takes input from the Text written in the TextField and a button,
but the developer can control the steps in between.
The protocol you use for that is UITextFieldDelegate.
1
First, when you tap the text field, the textFieldShouldBeginEditing method is called.
Think of it as asking whether to start Editing.
If it returns false, the keyboard doesn't even show up and input is impossible altogether.
If it returns true, the next steps proceed.
2
- textFieldDidBeginEditing is called.
Put the features to run when input starts into this function.
- textFieldShouldClear is called.
It's a function that asks whether to clear all the text.
Returning true wipes all the text, and returning false leaves the text alone.
3
When you press return on the keyboard or hit enter after typing on the keyboard,
textFieldShouldReturn is called.
But I have no idea what role the return value actually plays.
According to the official docs
'true if the text field should implement its default behavior for the return button; otherwise, false.'
but I have no idea what default behavior there even is. No matter how many times I tested, I couldn't see any change.
Skipping it for now.
4
When you call the TextField's endEditing(_ force: Bool) function,
the textFieldShouldEndEditing function is called.
It's a function that asks whether to end editing.
If it returns true, editing ends,
textFieldDidEndEditing is called, and the keyboard disappears.
If it returns false, it just ends there.