LoginSignup
0
1

More than 3 years have passed since last update.

可変長引数

Posted at

可変長引数とは

引数の個数を自由に設定出来るパラメーター

書き方

型名の後ろに ... を記述します。

func print(strings: String...) {
    if strings.count == 0 {
        return
    }

    print("first: \(strings[0])")

    for string in strings {
    print("elements: \(string)")
    }
}

print(strings: "apple", "banana", "orange")

// 出力結果
first: apple
elements: apple
elements: banana
elements: orange

参考

[増補改訂第3版]Swift実践入門 ── 直感的な文法と安全性を兼ね備えた言語 (WEB+DB PRESS plusシリーズ) 

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1