[Solved] Could you please explain the following code, especially the func statement


If you have any doubts regarding the UITextFieldDelegate see this example.

This func is called just before the typed charecter comes to the textfield. This func is mainly used for the validation.

Just to understand what happens I have written small code.

 func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
    print("TextField \(textField.text!), Range \(range), string \(string)")
    return true;
 }

When I type n the console prints ->>> TextField , Range (0,0), string n

Next If i press a the console prints ->>> TextField n, Range (1,0), string a

Next If i press v the console prints ->>> TextField na, Range (2,0), string v

In the second line where you are declaring text your taking the string present in the textView and the recently typed character and appending using the range and then code checks for the empty criteria.

1

solved Could you please explain the following code, especially the func statement