April 2026
Intermediate
683 pages
25h 29m
English
So far, we’ve offered examples in which a function was declared only once, with a single signature. This is the common and usual way of declaring functions. However, Swift also features the option of function overloading, declaring the same function multiple times with different parameter signatures.
Listing 5.40 demonstrates such an example, where the login function is overloaded with three different signatures.
func login(userName: String, password: String) { }func login(email: String, password: String) { }func login(forgotPasswordCode: String) { }
Listing 5.40 Overloaded Function Example
In this example,
you can use the first version if you have a user name and password at hand;
you can use the second ...
Read now
Unlock full access