Welcome to a Swift Deep Dive on Parameter Names. Now, in Swift, the parameter names of a function are incredibly 1
important. In the predecessor to Swift, Objective-C, which used to be the language that we used to make 2
iOS apps, 3
they weren't really big on parameter names. 4
Instead, you ended up with really, really long method and function names to describe exactly what the 5
function is supposed to do. But in Swift, it's meant to be about well-named parameters that clearly describe 6
the functionality. And this ability of Swift methods and functions, to be really clear, relies really heavily 7
on a particular feature of the Swift parameter names. 8
And it's the ability to have completely separate internal and external parameter names. 9
So in this case, instead of having a single parameter name, the word "name," we now have a external name 10
which is the name that will refer to the parameter when we call the function, and an internal name which is 11
the name that we'll use when we need to use the parameter within the function. 12
So if this is what our method definition looks like, then when we call the function, we would write something 13
like this. So in this case, the external parameter name is what we're using when we call the function, and the 14
internal parameter name is what we use when we need to use the value of that parameter within the function. 15
Now, you can also if you wanted to, actually omit the external parameter name altogether to be able to 16
call your function just by passing in a value without mentioning the name of the parameter at all. 17
So how would we do that? 18
Well, all that we would need to do is simply turn the external parameter name into an underscore. 19
And now we can call our function without using a parameter name at all. 20
And instead, all we have to do is just pass in the value that we want to use as the input. 21
So in this case, we still have an internal parameter name which we can use to refer to the value within 22
the function. 23
But when we call the method, we no longer have an external parameter name. 24
So in the next lesson, we're actually going to use this in practice and we're going to update our delegate 25
methods to be more in line with the way that Apple does things.