Function Parameters
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 ...
Get Swift Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.