Swift 4.0 対応しようとしたら大変な目に遭った話

Af64bc38c0ffcfcabdf430759ee491ce?s=47 Elvis Shi
September 16, 2017

Swift 4.0 対応しようとしたら大変な目に遭った話

Swift 4対応するときのエモい話

Af64bc38c0ffcfcabdf430759ee491ce?s=128

Elvis Shi

September 16, 2017
Tweet

Transcript

  1. 4XJGUରԠ͠Α͏ͱͨ͠Β େมͳ໨ʹૺͬͨ࿩ for iOSDC Japan 2017

  2. ΤϞ͍࿩ ࠓ೔͸ ˞4XJGUͷݴޠ࢓༷ͷ࿩͸͋Γ·ͤΜɻ

  3. override init() { super.init() emplyedBy = "MAGES. 5pb. Game div"

    job = "iOS Developer" twitter = "@lovee" qiita = "@lovee" github = "el-hoshino" additionalInfo = "དྷ݄స৬͠·͢ʘ(^o^)ʗ" class Speaker: Developer { } }
  4. 4XJGUରԠɺ
 ͍ͯ͠·͔͢ʁ

  5. ࢲ͸88%$௚ޙ͔Β
 ͍ͯ͠·͢ʂ

  6. ˠ ˠ ˠ     ☠

  7. ௐࢠʹ৐ͬͯ
 ͠·ͬͨ

  8. ຊ೔ͷ ओ໾

  9. 1MPU 3FWJFX "QQMJDBUJPO 7JB %BUBJOQVU "TTJTUBOU

  10. 13"7%" "%7ήʔϜγφϦΦ
 ϨϏϡʔΞϓϦ༻
 ϑϨʔϜϫʔΫ

  11. 13"7%" νϟϓλʔϑϩʔͰ ಡΈ͍ͨষΛબͿ

  12. 13"7%" ͦͷষͷ࠷ॳͷ
 γφϦΦϑΝΠϧΛ ಡΉ

  13. 13"7%" ηϦϑʹධՁΛ ͚ͭΔ

  14. 13"7%" ͜ͷϑΝΠϧࣗମٴͼ
 ͜ͷϑΝΠϧʹ
 ొ৔ͨ͠ΩϟϥΛධՁ

  15. 13"7%" ࣍ͷϑΝΠϧ΁ ਐΉ

  16. 13"7%" ষ຤Ͱ͜ͷষͷ ײ૝Λ࢒͢

  17. 13"7%" ৽͍͠νϟϓλʔ͕ ղআ͞Εɺ
 νϟϓλʔϑϩʔ΁

  18. 13"7%" UITableView
 UIPageView UISlider UIPanGestureRecognizer FUDʜ

  19. 13"7%"։ൃ࣌αϚϦʔ ▸ ։ൃ։࢝࣌ɿ4XJGU຤ظ ▸ ౰࣌ґଘ؀ڥɿࣗ࡞ϑϨʔϜϫʔΫ&MUBTP ݩڟͦͷҰ ݩڟͦͷೋ

  20. 13"7%"։ൃ౰ॳͷεΩϧ͸ະख़ͩͬͨ ▸ J04։ൃʹͦͦ͜͜׳Ε͖ͯ࢝Ίͨࠒ ▸ ઃܭʹؾΛ഑Γ࢝Ί͕ͨܦݧઙ͔ͬͨͨΊ·ͩ؁͔ͬͨ ▸ σʔλϑϩʔ͕ෳࡶͰಈ࡞Λ௥͍ʹ͔ͬͨ͘ ▸ ʮڞ௨ͷઃఆ͔ͩΒΈΜͳ࢖͏ʯͱ͍͏୯७ͳཧ༝Ͱ4JOHMFUPOΛ࢖͍΍ ͕ͬͨ

    ▸ ͱΓ͋͑ͣ4XJGUʹ্͛ͯΈͨΒ΄ͱΜͲमਖ਼͍Βͣ ▸ ͔͔ͤͬͩ͘ΒؾʹͳͬͨϙΠϯτ௚ͦ͏ͱࢥͬͨ ▸ ্هͷઃܭͷ؁͞Ͱେ෯ͳॻ͖׵͑Λڧ͍ΒΕͨ
  21. 13"7%"։ൃ࣌αϚϦʔ ▸ ։ൃ։࢝࣌ɿ4XJGU຤ظ ▸ ౰࣌ґଘ؀ڥɿࣗ࡞ϑϨʔϜϫʔΫ&MUBTP ݩڟͦͷҰ ݩڟͦͷೋ

  22. &MUBTPͱ͸Կ͔ ▸ 4XJGUʹ͋Γͦ͏Ͱͳ͔ͬͨ৭ΜͳศརͳػೳΛ੝ΓࠐΜͩ൚༻ϑϨʔϜϫʔΫ ▸ CGPointಉ࢜ͳͲͷ଍͠ࢉҾ͖ࢉ ▸ ܾ·ͬͨൣғ಺ͷཚ਺ੜ੒Int.makeRandom(within: 0 ..< 10)

    ▸ ഑ྻͷγϟοϑϧ[1, 2, 3, 4, 5].shuffled ▸ ͳͲͳͲʜ ▸ ࠷ॳ͸ϋοΧιϯͷ࣌ͷίʔσΟϯάޮ཰ͷͨΊʹ࡞ͬͨ ▸ ࡞ͬͯΔ͏ͪʹʮ࣮຿ʹ΋ศར͡ΌͶʯͱࢥͬͯ࢖͍࢝Ίͨ IUUQTHJUIVCDPNFMIPTIJOP&MUBTP
  23. &MUBTPͷԿ͕มΘ͔ͬͨ ▸ ͿͬͪΌ͚࡞ͬͨ౰ॳ͸Կ΋ਂ͘ߟ͑ͣʹػೳ੝ΓࠐΜͰͨ ▸ 4XJGUˠͷ࣌ͷίʔυमਖ਼͚ͩͰେมͩͬͨͷͰͦΕʹઐ೦ͨ͠ ▸ 4XJGUˠͷࠓ͸ίʔυमਖ਼΄΅ͳ͔ͬͨͷͰʮ༨ܭʯͳ͜ͱߟ͑࢝Ίͨ ▸ ͜ͷ"1*ઃܭ͸ຊ౰ʹެࣜΨΠυϥΠϯʹଇͬͯΔ͔Ͳ͏͔ ▸

    ͜Ε͸ຊ౰ʹ&MUBTPʹೖΕΔ΂͖ػೳ͔ʢಠཱͤ͞Δ΂͖͔ʣ ▸ 5BSHFUFE&YUFOTJPOTͷಋೖʢxxx.rx.doSth()Έ͍ͨͳॻ͖ํʣ ▸ ࢖͍ํ͕ΨϥϦͱมΘͬͯ&MUBTPґଘͷϓϩδΣΫτ͕େมͳ͜ͱʹ IUUQTHJUIVCDPNFMIPTIJOP&MUBTP
  24. /PU"VUP-BZPVUΛ৽ͨʹಋೖͨ͠ ▸ ౰ॳ΋શͯͷϨΠΞ΢τ͸ίʔυϕʔεͩͬͨ ▸ ϨΠΞ΢τ͸શͯlayoutSubviews()ͷoverrideͰରԠͨ͠ ▸ ೝ͕ࣝ଍Γͣɺ௚઀layoutSubviews()Λݺͼग़͢Օॴ΋͋ͬͨ ▸ ࢠϏϡʔΛϓϩύςΟʔͱͯ͠อ࣋͢Δඞཁ͕͋ͬͨ ▸

    ผͷϓϩδΣΫτͷ੍࡞࣌ʹ/PU"VUP-BZPVUΛ࡞ͬͨ ▸ layoutSubviews()Λඞͣ͠΋override͢Δඞཁ͕ͳ͘ͳͬͨ ▸ ࢠϏϡʔͷϨΠΞ΢τΛ਌ϏϡʔͷϓϩύςΟʔͱͯ͠อ࣋Ͱ͖ΔͨΊ
 ࢠϏϡʔࣗମΛϓϩύςΟʔͱͯ͠อ࣋͢Δඞཁ͕ͳ͘ͳͬͨ ▸ ʲએ఻ʳචऀݱࡏͷϝΠϯ044ϓϩδΣΫτʂ IUUQTHJUIVCDPNFMIPTIJOP/PU"VUP-BZPVU
  25. ݁Ռɿ ຆͲॻ͖׵͑ʹ

  26. FlowContentControllerʢچʣ fileprivate lazy var chapterButtons: [FlowChapterButton] = { let chapters

    = GlobalSettings.shared.chapterMetas let buttons = chapters.enumerated().map { (i, chapterMeta) -> FlowChapterButton in let button = FlowChapterButton(meta: chapterMeta) button.setOnTappedAction({ [weak self] _ in self?.didSelectChapter(i) }) return button } return buttons }()
  27. FlowContentControllerʢ৽ʣ private lazy var chapterButtons: [FlowChapterButton] = { let chapters

    = self.model.getChapters(for: self) let buttons = chapters.map { (chapter) -> FlowChapterButton in let button = self.makeButton(for: chapter) return button } return buttons }()
  28. FlowControllerʢچʣ override func viewDidLoad() { super.viewDidLoad() // Do any additional

    setup after loading the view. do { let controller = self.flowContentController controller.delegate = self controller.dataSource = self.dataSource self.addChildViewController(controller) self.flowView.contentView = controller.view controller.didMove(toParentViewController: self) } do { let controller = self.pageHeaderController controller.setHeaderTitleString("νϟϓλʔબ୒") self.addChildViewController(controller) self.flowView.header = controller.view controller.didMove(toParentViewController: self) } }
  29. FlowControllerʢ৽ʣ override func viewDidLoad() { super.viewDidLoad() self.setupContentController() self.setupHeaderController() }

  30. ScenarioModelʢ৽چࠩ෼ʣ

  31. ➡ େมͩͬͨ ͚Ͳ ಡΈ΍͢͞ େ෯ʹ㽉

  32. ͱࢥͬͨΒࠓ౓͸ J1IPOF9ͷొ৔ͩ

  33. None
  34. Ͱ΋ؤுͬͯ೔Ͱ
 /PU"VUP-BZPVUΛ
 TBGF"SFB*OTFUTʹ
 ରԠͤͨ͞

  35. None
  36. چ ৽

  37. ʲએ఻ʳ
 /PU"VUP-BZPVU
 ޷ධެ։தʂ IUUQTHJUIVCDPNFMIPTIJOP/PU"VUP-BZPVU

  38. ڭ܇ͦͷҰ ▸ 4JOHMFUPO͸͖ͪΜͱ࢖͏΂͖͔Λߟ͔͑ͯΒ࢖͑ ▸ ʮΠϯελϯε͕Ұݸ͔͠ͳ͍ʯ͸4JOHMFUPOΛ࢖͏ཧ༝ʹͳΒͳ͍ ▸ ʮΈΜͳڞ௨ͯ͠࢖͏ʯ΋4JOHMFUPOΛ࢖͏ཧ༝ʹͳΒͳ͍ ▸ ʮ୭΋͍ͭ͜ʹ੹೚Λ࣋ͯΔʹ஌Γਚ͘͢͜ͱ͕ڐ͞ΕΔʯ΋ͷ͚ͩ 4JOHMFUPOΛ࢖͍͍ͬͯ

  39. ڭ܇ͦͷೋ ▸ ઃܭ͸͖ͪΜͱอक͢Δ࣌ͷࣗ෼Λߟ͑ͯઃܭ͠Ζ ▸ ѱ͍ઃܭ͸ॻ͘ͱ͖͸ศར͔΋͠Εͳ͍͕อक࣌ʹࢮ͵ ▸ อक࣌ʹͦͷѱ͍ઃܭΛ໨ʹ͢ΔͱͦΕΛॻ͍ͨࣗ෼ΛͿΜԥΓͨ͘ͳΔ ▸ Ͱ΋·͔͋ͱݴͬͯͿͬͪΌ͚ͦΕ͸ࣗ෼ͷεΩϧʹґଘ͢Δ΋ͷ͔ͩΒ ࠓ͸͖ͪΜͱͨͭ͠΋ΓͰ΋ଟ෼೥ޙͷอक࣌ʹྺ࢙͸܁Γฦ͢

    ▸ ͦΕͰ΋ͦΕ͸εΩϧΞοϓͷূڌ͔ͩΒڪΕͣʹ੒௕͠·͠ΐ͏
  40. ڭ܇ͦͷࡾ ▸ 'SBNFXPSLͷଟ༻͸ґଘੑ͕େมͳ͜ͱʹͳΔ ▸ ࢖͍࢝Ίͨͱ͖͸͔֬ʹศར͚ͩͲґଘ͢Δ'SBNFXPSL͕૿͑Δͱ
 ͦͷ෼͚ͩґଘؔ܎΋૿͑Δ ▸ 'SBNFXPSLʹมߋ͕͋Δͱ࢖ͬͯΔϓϩδΣΫτͷमਖ਼΋༨ّͳ͘͞ΕΔ ▸ 'SBNFXPSLΛࣗ࡞͢ΔͱϓϩάϥϜઃܭʹ͍ͭͯΑΓਂ͘ߟ͑ͤͯ͘͞ΕΔ

    ▸ 'SBNFXPSL͸ͦΕΛར༻͢ΔશͯͷϓϩδΣΫτʹӨڹΛٴ΅͢ͷͰ "1*ͷઃܭʹ͸ͱͯ΋ؾΛ͚ͭΔඞཁ͕͋Δ
  41. ॳ৺ऀ΁ͷΞυόΠε ▸ ͱʹ͔͕͘Ή͠ΌΒʹ͍ͬͺ͍ॻ͖·͠ΐ͏ɻ ▸ Կ΋ߟ͑ͣʹॻ͘ͷͰ͸ͳ͘ɺྫ͑)PX͕ཧղͰ͖ͳͯ͘΋ɺ8IBUͱ8IZ Λཧղ͢Δ౒ྗΛ͠·͠ΐ͏ɻ ▸ ΍Γ͍ͨ͜ͱ͕Ͱ͖͔ͨΒͬͯࢥߟఀࢭͤͣɺΑΓྑ͍ॻ͖ํ͕ͳ͍͔΋ߟ͑· ͠ΐ͏ɻ ▸

    ͍ͬͺ͍นʹͿ͔ͭͬͯઃܭʹ͍ͭͯͷཧղΛਂΊ·͠ΐ͏ɻ ▸ 2JJUB΍5FSB5BJM΋ྑ͍Ͱ͕͢ɺެࣜυΩϡϝϯτ΋ͪΌΜͱಡΈ·͠ΐ͏ɻ ▸ ൒೥લͷࣗ෼͕ॻ͍ͨίʔυ͕ΫιͩͱࢥΘͳ͔ͬͨΒ੒௕͕ࢭ·ͬͨূڌʂ
  42. ͋Γ͕ͱ͏
 ͍͟͝·ͨ͠ʂ