> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/features/variadic-parameter.md).

# 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](/ios/features/destructuring.md)
  {% 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 %}
