100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Swift

Parameters and Return Values in Swift

Master default values, variadic parameters, in-out parameters, and multiple return values via tuples in Swift functions.

Functions & ClosuresIntermediate10 min readJul 8, 2026
Analogies

Introduction

Swift functions offer flexible ways to define parameters and return values beyond a single required input and a single output. You can give parameters default values, accept a variable number of arguments with variadic parameters, pass values by reference using in-out parameters, and return multiple values at once using tuples. These features let you design cleaner, more flexible function signatures.

🏏

Cricket analogy: A bowler's function signature can default to a standard field placement unless the captain overrides it, accept a variadic number of overs bowled in a spell, use an inout parameter to let a runner directly adjust the scoreboard, and return a tuple of both runs conceded and wickets taken at once.

Syntax

swift
func greet(name: String = "World") -> String { ... }

func sum(_ numbers: Int...) -> Int { ... }

func swapValues(_ a: inout Int, _ b: inout Int) { ... }

func minMax(of numbers: [Int]) -> (min: Int, max: Int) { ... }

Explanation

A default parameter value lets callers omit that argument entirely, in which case Swift substitutes the default. A variadic parameter, written with three dots after the type (e.g. Int...), accepts zero or more values of that type, which are made available inside the function as an array. An in-out parameter, marked with inout, lets a function modify a caller's variable directly rather than working on a copy; callers must pass an & before the argument to indicate it may be mutated. Finally, a tuple return type lets a single function return multiple named values at once, avoiding the need for a custom struct just to bundle a couple of related results.

🏏

Cricket analogy: Omitting the overrideField argument lets Swift substitute the default field setting; wickets... gathers a variadic number of dismissals into an array inside the function; an inout runsScored parameter marked with & lets an over directly update the caller's scoreboard; and a tuple return hands back (runs, wickets) together without a custom struct.

Example

swift
func greet(name: String = "World") -> String {
    return "Hello, \(name)!"
}

func sum(_ numbers: Int...) -> Int {
    return numbers.reduce(0, +)
}

func swapValues(_ a: inout Int, _ b: inout Int) {
    let temp = a
    a = b
    b = temp
}

func minMax(of numbers: [Int]) -> (min: Int, max: Int) {
    return (numbers.min()!, numbers.max()!)
}

print(greet())
print(sum(1, 2, 3, 4))

var x = 5
var y = 10
swapValues(&x, &y)
print(x, y)

let result = minMax(of: [3, 7, 1, 9])
print(result.min, result.max)

Output

swift
Hello, World!
10
10 5
1 9

Key Takeaways

  • Default parameter values let callers omit arguments, e.g. name: String = "World".
  • Variadic parameters (Int...) accept a variable number of values as an array inside the function.
  • inout parameters allow a function to modify the caller's variable directly, requiring & at the call site.
  • Tuples let a function return multiple named values without defining a custom type.
  • These features make function signatures more flexible and expressive.

Practice what you learned

Was this page helpful?

Topics covered

#Swift#SwiftProgrammingStudyNotes#Programming#ParametersAndReturnValuesInSwift#Parameters#Return#Values#Syntax#StudyNotes#SkillVeris