Functions and Closures
Function Parameters
Function parameters receive values from the call site and let one function work with different inputs.
Pass values into a function
function_parameters.swift
func addTax(price: Int, tax: Int) -> Int {
return price + tax
}
let price =
let tax = 3
let total = addTax(price: price, tax: tax)
print("price=\(price)")
print("total=\(total)")
func addTax(price: Int, tax: Int) -> Int {
return price + tax
}
let price =
let tax = 3
let total = addTax(price: price, tax: tax)
print("price=\(price)")
print("total=\(total)")
func addTax(price: Int, tax: Int) -> Int {
return price + tax
}
let price =
let tax = 3
let total = addTax(price: price, tax: tax)
print("price=\(price)")
print("total=\(total)")
parameters
Parameters are local names inside the function body. Each call supplies the actual values used for that run.