November 2016
Intermediate to advanced
480 pages
14h 42m
English
Functions begin to take on more life when they have parameters. You use parameters to give a function some inputs. We call these parts of a function “parameters” to indicate that they can change value depending on the data the caller passes into the function. The function takes the data passed to its parameters to execute a task or produce a result.
Create a function that prints a more personal greeting by using a parameter.
Listing 12.2 Using a parameter
import Cocoa
func printGreeting() {
print("Hello, playground.")
}
printGreeting()
func printPersonalGreeting(name: String) {
print("Hello \(name), welcome to your playground.")
}
printPersonalGreeting(name: "Matt")
printPersonalGreeting(name:) takes ...
Read now
Unlock full access