LoginSignup
7
8

More than 5 years have passed since last update.

[Swift]省略記法で$0.0と$0.1を使う例

Last updated at Posted at 2015-10-04

enumerate().forEach

enumerate().forEachを使うと、省略記法で$0.0と$0.1を使う場合がある。初見だと最初戸惑ったのでメモ。

let array = ["カレー","ラーメン","ハンバーグ"]

array.enumerate().forEach { (index, element) in
    print("index:\(index) element:\(element)")
}

//省略記法
array.enumerate().forEach {
    print("index:\($0.0) element:\($0.1)")
}

出力結果

index:0 element:カレー
index:1 element:ラーメン
index:2 element:ハンバーグ
7
8
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
7
8