Swift3.0に向けて enumerateを使い始めよう

218
-1

Published on

shibuya.swift #2 での発表内容
http://shibuya-swift.connpass.com/event/21979/

Published in: Mobile
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
218
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Swift3.0に向けて enumerateを使い始めよう

  1. 1. 自己紹介 • @mo_to_44 • 株式会社ネクストで  HOME Sという
 不動産検索アプリのiOSエンジニアをやっています
  2. 2. 個人でもアプリ作ってます   リボカメ - Revolver Camera • リボルバーを模したUI • フィルターをリアルタイムで 切り替え、確認できる • Apple Watch対応
  3. 3. swift-evolution https://github.com/apple/swift-evolution
  4. 4. Swift 3.0 proposal • https://github.com/apple/swift-evolution/tree/ master/proposals から見ることができる • 0004 と 0007 が気になった
  5. 5. 0004: Remove the ++ and -- operators Status: Accepted
  6. 6. 0007: Remove C-style for-loops with conditions and incrementers Status: Under review 
 (December 7, 2015 -- December 10, 2015)
  7. 7. Today
  8. 8. 0007: Remove C-style for-loops with conditions and incrementers Status: Accepted
  9. 9. と、いうことで
  10. 10. こんなんが書けなくなる😱
  11. 11. 困りそうなこと
  12. 12. あんまりない😜 for-in, forEach, map, filter よりどりみどり
  13. 13. Swift Advent Calendar 2015 2日目にまとめました http://qiita.com/mo_to_44/items/cf83b22cb34921580a52
  14. 14. ちょっと困りそうなこと • 配列内の要素のindexを取得したい • indexが奇数の要素だけ取得したい などなど などなど、indexによってデータを取得、更新したり、 indexが配列を操作する際に重要な場合
  15. 15. indexが奇数の要素だけ取得 1. 空の配列 newArray を用意 2. for-inで各要素のindexを取得 3. indexが奇数の要素を newArray に追加
  16. 16. 長っ
  17. 17. こんな時に
  18. 18. enumerateが使える
  19. 19. enumerate • SequenceType Protocolに定義されている • indexと要素のペア(タプル)の配列を取得するこ とができる
  20. 20. indexが奇数の要素だけ取得
 enumerate使用版 1. 空の配列 newArray を用意 2. enumerateを使用し、indexと要素のタ プルの配列のfor-inを回す 3. indexが奇数の要素を newArray に追加
  21. 21. まだちょっと長い
  22. 22. indexが奇数の要素だけ取得
 enumerate使って1行に 1. enumerateを使用し、indexが奇数のタ プルをfilterで絞り込み 2. mapで要素のみを取り出す
  23. 23. (index, element) $0.0 $0.1 タプルの要素へのアクセス
  24. 24. indexが奇数の要素だけ取得
 enumerate使って1行に 1. enumerateを使用し、indexが奇数のタ プルをfilterで絞り込み 2. mapで要素のみを取り出す
  25. 25. シンプル 👍
  26. 26. まとめ
  27. 27. enumerate • SequenceTypeのExtensionで定義されている • index と 要素のペア(タプル)の配列を取得できる
  28. 28. Swift 3.0 • ++ と -- がなくなる • C言語スタイルのfor文がなくなる(かもしれない)
  29. 29. Swift 3.0に向けて • C言語スタイルのfor文ではなく、enumerateを積極 的に使っていく • 同様に ++ や -- も使わないようにする • swift-evolution/proposal に目を通して、なくなる かもしれない文法はなるべく使わないようにする
  30. 30. おわり
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×