December 2015
Intermediate to advanced
400 pages
13h 3m
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 upon 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("Matt")
printPersonalGreeting(_:) takes a single ...
Read now
Unlock full access