Tsallaka zuwa abun ciki
Justice Tech School

Default and Variadic Parameters

Give defaults and use ... for any number of values.

Example
func box(w: Int, h: Int = 1) -> String { "\(w)x\(h)" }
func sum(_ n: Int...) -> Int { n.reduce(0, +) }
print(box(w: 3))
print(sum(1, 2, 3))

Exercise

Variadic.

_ n: Int

Quiz Test

What type is n inside?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.