iOS ● ○ ○ Swift 6

Kodebits Day 49: Variadic Sum

Jun 29 2026
Practice functions with a short swift challenge.

What does this print?

func sum(_ nums: Int...) -> Int {
  var total = 0
  for n in nums {
    total += n
  }
  return total
}
print(sum(3, 5, 2))
print(sum(10))


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

10
10

Explanation:

Variadic parameters accept zero or more values as an array.

[/spoiler]


Further Reading