Explanation of Code on Page 78 (UITextFieldDelegate)

Hi,
The syntax for UITextFieldDelegate is gives as
“f​u​n​c​ ​t​e​x​t​F​i​e​l​d​(​t​e​x​t​F​i​e​l​d​:​ ​U​I​T​e​x​t​F​i​e​l​d​,​
​ ​ ​ ​ ​ ​ ​ ​s​h​o​u​l​d​C​h​a​n​g​e​C​h​a​r​a​c​t​e​r​s​I​n​R​a​n​g​e​ ​r​a​n​g​e​:​ ​N​S​R​a​n​g​e​,​
​ ​ ​ ​ ​ ​ ​ ​r​e​p​l​a​c​e​m​e​n​t​S​t​r​i​n​g​ ​s​t​r​i​n​g​:​ ​S​t​r​i​n​g​)​ ​-​>​ ​B​o​o​l​ ​{​

​ ​ ​ ​p​r​i​n​t​(​"​C​u​r​r​e​n​t​ ​t​e​x​t​:​ ​\​(​t​e​x​t​F​i​e​l​d​.​t​e​x​t​)​"​)​
​ ​ ​ ​p​r​i​n​t​(​"​R​e​p​l​a​c​e​m​e​n​t​ ​t​e​x​t​:​ ​\​(​s​t​r​i​n​g​)​"​)​

​ ​ ​ ​r​e​t​u​r​n​ ​t​r​u​e​

​ ​ ​ ​l​e​t​ ​e​x​i​s​t​i​n​g​T​e​x​t​H​a​s​D​e​c​i​m​a​l​S​e[…]”

Excerpt From: Keur, Christian. “iOS Programming: The Big Nerd Ranch Guide (Nikhil Pandey’s Library).” Big Nerd Ranch Guides, 2015-12. iBooks.
This material may be protected by copyright.

Can anyone please explain what is basic syntax , which is given below
“f​u​n​c​ ​t​e​x​t​F​i​e​l​d​(​t​e​x​t​F​i​e​l​d​:​ ​U​I​T​e​x​t​F​i​e​l​d​,​
​ ​ ​ ​ ​ ​ ​ ​s​h​o​u​l​d​C​h​a​n​g​e​C​h​a​r​a​c​t​e​r​s​I​n​R​a​n​g​e​ ​r​a​n​g​e​:​ ​N​S​R​a​n​g​e​,​
​ ​ ​ ​ ​ ​ ​ ​r​e​p​l​a​c​e​m​e​n​t​S​t​r​i​n​g​ ​s​t​r​i​n​g​:​ ​S​t​r​i​n​g​)​ ​-​>​ ​B​o​o​l​ ​{​
}
What is shouldChangeCharactersInRage and then it’s range: NSRange, also replacementString string: String. Are shouldChangeCharactersInRange and replacementString are functions inside the textFieldDelegate and which take “range” and “string” as parameters, which are of type NSRange and String respectively.

the name of the first parameter variable | the type of the textField parameter variable | | V V textField: UITextField

In Swift, you can give a parameter variable two names: an external name and an internal name. The external name is used when you call the function; the internal name is used inside the function:

the *external* name of the second parameter variable | the *internal* name of the second parameter variable | | V V s​h​o​u​l​d​C​h​a​n​g​e​C​h​a​r​a​c​t​e​r​s​I​n​R​a​n​g​e​ ​r​a​n​g​e​:​ ​N​S​R​a​n​g​e​, ^ | the type of the second parameter variable

Here is a playground example:

[code]func multiplyLength(len: Int, byWidth w: Int) -> Int {
return len * w
}

multiplyLength(10, byWidth: 3) //=> 30[/code]

[code]the external name of the third parameter variable
| the internal name of the third parameter variable
| |
V V
r​e​p​l​a​c​e​m​e​n​t​S​t​r​i​n​g ​s​t​r​i​n​g​:​ ​S​t​r​i​n​g​
^
|
the type of the third parameter variable

[/code]
​ ​-> Bool Return type

The name of the function is considered to be:

which tells you how to call the function: no label for first argument, second argument labeled with shouldChangeCharactersInRage; third argument labeled with replacementString:, for instance:

[code]

yourTextField.delegate.textField(tf, shouldChangeCharactersInRange:r, replacementString:“hello”)[/code]

By default, you are not allowed to label the first argument when you call a function, and you have to label the other arguments. However, if you define a function and specify two names for the first parameter variable, then you must label the first argument in the function call. Also, if you specify an external name of _ for a parameter variable, then you cannot label the argument in the function call. Here is an example:

[code]
two names two names two names
| | | | | |
V V V V V V
func addNumbers(num1 x: Int, _ y: Int, _ z: Int) -> Int {
return x + y + z
}

addNumbers(num1: 10, 20, 30) //=> 60[/code]

The name of the function is considered to be:

The name tells you that there are three arguments, and that when you call the function you have to label the first argument with num1:, and you cannot label the 2nd and 3rd arguments.

A really good source for details about the Swift language is here:

developer.apple.com/library/ios … CH10-ID158