0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

なんかいつも忘れるクソ脳みそのためのtuple

Last updated at Posted at 2023-11-25

まあチュートリアルをまとめただけ。意味がない

タプルは、複数の値を1つのまとまりでグループ化できる。
任意の順序で、異なる任意の方を組み合わせることができる。

タプルの表現方法は2種類ある。

let http404error = (404,"Not Found")
let (statusNumber,statusMessage) = http404error
let http404error = (statusNumber:404,statusMessage: "Not Found")

タプルの一部だけが必要な場合は、アンダースコアで無視することが可能。(おそらく外部のクラスなどを使用する際に有効的)

let http404error = (404,"Not Found")
let (statusNumber, _) = http404error

各種アクセスには、インデックスを使用する例と、定義した名前を使用する2種類がある。

let http404error = (404,"Not Found")
let (statusNumber,statusMessage) = http404error
print(The status is \(http404error.0))
// -> "The status is 404"
print(The status is \(http404error.statusNumber)
// -> "The status is 404"
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?