# Variadic Parameter

{% hint style="info" %}
* The **values** passed to a variadic parameter are made available within the function’s body as an **array** of the appropriate type.
* A function can have **multiple** variadic parameters.
* The **first parameter** that **comes after** a **variadic parameter** must have an **argument label**.
{% endhint %}

{% tabs %}
{% tab title="code" %}
```swift
// ⭐️ variadic parameter
func f1(_ ints: Int...) -> Int { return 1 }

func f2(_ ints: Int...) -> Int {     // `ints` is of type `[Int]`
    // ⛔ cannot convert value of type '[Int]' 
    //    to expected argument type 'Int'
    return f1(ints) 
}

// The only way to solve this (for now) is to add 
// another method overload accepting an array
```
{% endtab %}

{% tab title="📘 手冊" %}
* Swift ⟩ [Variadic Parameters](https://docs.swift.org/swift-book/LanguageGuide/Functions.html#ID166)
{% endtab %}

{% tab title="📗 參考" %}
* [Passing Variadic Parameters around in Swift](https://blog.eidinger.info/passing-variadic-parameters-around-in-swift)
{% endtab %}

{% tab title="👥 相關" %}
* [destructuring](destructuring "mention")
{% endtab %}

{% tab title="🗣 討論" %}
* Swift forum ⟩ [Another attempt at passing arrays as varargs](https://forums.swift.org/t/another-attempt-at-passing-arrays-as-varargs-with-implementation/26718)
{% endtab %}
{% endtabs %}
