Parameters
Parameters
Parameters is a free Swift Academy lesson on CoddyKit. This is lesson 1 of 1. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, and your progress syncs across the web and the CoddyKit app. The Swift Academy course includes 1 lessons in total.
Introduction
Hello,
In this section, we will learn about the useful features of parameters in Swift language.
The first we will learn are variadic parameters.
A variadic parameter is a parameter that can take 0 or more values of the same type. It can be used when we cannot predict exactly how many parameters it will take.
example
A function can have a maximum of one variadic parameter.
Let's do an example.
func arithmeticMean(_ numbers: Double...) -> Double {
var total: Double = 0
for number in numbers {
total += number
}
return total / Double(numbers.count)
}
var result = arithmeticMean(1, 2, 3, 4, 5)
print(result)
// returns 3.0, which is the arithmetic mean of these five numbers
result = arithmeticMean(3, 8.25, 18.75)
print(result)
// returns 10.0, which is the arithmetic mean of these three numbersWarning
Variadic parameter actually creates a constant as a Constant array.
in out parameter
Function parameters are fixed by default.
Trying to change the parameter of a function inside the function body will result in a compile-time error.
If we want to write a function and want to change the value of the parameter of that function and we want this change to remain permanently even after the function is completed, we need to use an in-out parameter.
example
When calling the function, the argument is passed to the name of the variable with the & sign. This means that the variable can be changed by the function.
In-out parameters cannot have a default value. Variadic parameters cannot be marked as inout.
/*
In the example below, the value of someInt
is assigned to anotherInt and the value
of anotherInt to someInt.
*/
// Note that these two types have variables.
func swapTwoInts(_ a: inout Int, _ b: inout Int) {
let temporaryA = a
a = b
b = temporaryA
}
var someInt = 3
var anotherInt = 107
// Note that the corresponding arguments
//are passed ampersant while calling the function.
swapTwoInts(&someInt, &anotherInt)
print("someInt is now \(someInt), and anotherInt is now \(anotherInt)")
// Prints "someInt is now 107, and anotherInt is now 3"Congratulations
Congratulations 🎉
In this lesson, we have learned parameter features on Swift.
See you in the next lesson.

Learn Swift with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 122
- Lessons
- 409
Frequently Asked Questions
Is the “Parameters” lesson free?
Yes — any 3 lessons of the Swift Academy learning path, including “Parameters”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Swift Academy course includes 1 lessons in total.
What will I learn in “Parameters”?
Parameters You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Swift Academy?
No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 1.
How long does the “Parameters” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Swift Academy lesson?
Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.