Swift3.0に向けて enumerateを使い始めよう
33
-
Upload
motoki-narita -
Category
Mobile
-
view
6.413 -
download
0
Transcript of Swift3.0に向けて enumerateを使い始めよう
Swift 3.0 proposal
• https://github.com/apple/swift-evolution/tree/master/proposals から見ることができる
• 0004 と 0007 が気になった
0007: Remove C-style for-loops with conditions and incrementers
Status: Under review (December 7, 2015 -- December 10, 2015)
Swift Advent Calendar 2015 2日目にまとめましたhttp://qiita.com/mo_to_44/items/cf83b22cb34921580a52
ちょっと困りそうなこと
• 配列内の要素のindexを取得したい
• indexが奇数の要素だけ取得したい などなど
などなど、indexによってデータを取得、更新したり、indexが配列を操作する際に重要な場合
indexが奇数の要素だけ取得enumerate使用版
1. 空の配列 newArray を用意 2. enumerateを使用し、indexと要素のタプルの配列のfor-inを回す
3. indexが奇数の要素を newArray に追加
Swift 3.0に向けて• C言語スタイルのfor文ではなく、enumerateを積極的に使っていく
• 同様に ++ や -- も使わないようにする
• swift-evolution/proposal に目を通して、なくなるかもしれない文法はなるべく使わないようにする