LoginSignup
2
2

More than 5 years have passed since last update.

swiftでのタプル

Posted at

1.タプルを定義する


let 変数 = (値1,値2,...)

タプルの定義は()の中に値を列挙する。

2.タプルを参照する


let 変数 = タプル変数.数値

タプルで定義された変数から値を取り出す場合は、ピリオドの後に数値を指定する。

3.使用例


//タプルの定義
let sampleTuple = ("Japan",48,"MachuPicchu")
//タプルから取り出す
let country = sampleTuple.0
let number  = sampleTuple.1
let remains = sampleTuple.2
//出力
print(country) // -> Japan
print(number)  // -> 48
print(remains) // -> MachuPicchu
2
2
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
2
2