Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift

0cf23fed58f84e729aa59ba5d8d0baaf?s=47 ukitaka
April 16, 2018

Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift

0cf23fed58f84e729aa59ba5d8d0baaf?s=128

ukitaka

April 16, 2018
Tweet

Transcript

  1. Responder ChainΛ࢖ͬͯ ίʔυΛεοΩϦ͍ͤͨ͞ HAKATA.swift @ukitaka

  2. twitter: @ukitaka_ github: @ukitaka Yuki Takahashi

  3. ࣗݾ঺հ ❤ ؔ਺ܕϓϩάϥϛϯάɺDDD ✏ ܕγεςϜɺίϯύΠϥ ௿ϨΠϠʔ

  4. ࠓ೔ͷ࿩

  5. ͍͖ͳΓͰ͕͢ɺ ͜ΜͳέʔεΛߟ͑ͯΈΔ

  6. Cellͷதͷ ϘλϯΛλοϓͨ͠Β Alert / ActionSheetग़͍ͨ͠

  7. None
  8. ͋Γ͕ͪ

  9. ஍ຯʹΊΜͲ͍͘͞ • UIAlertControllerΛग़͢ʹ͸ViewControllerͰ ॲཧΛ͢Δඞཁ͕͋Δ • Cell͸ViewControllerͳΜͯ஌Βͳ͍ • ViewController΋CellͷϘλϯΛ(ී௨͸)௚઀ࢀ র͍ͯ͠ͳ͍

  10. Α͋͘Δରॲ๏ • DelegateΛҾճ͢ • ֊૚͕ਂ͘ͳΕ͹ͳΔ΄Ͳਏ͍ • Viewߏ଄ͷมԽʹऑ͍

  11. ͳΜͱ͔͍ͨ͠

  12. ݪ఺ʹཱͪฦͬͯMVC

  13. MVCͰ͸Ͳ͏͋Δ΂͖ʁ

  14. None
  15. None
  16. ϢʔβΞΫγϣϯͷॲཧ • MVCʹ͓͚ΔControllerͷΑ͏ͳΦϒδΣΫ τʹ௨஌Λͯ͠ϢʔβΞΫγϣϯड͚ͱΔͷ ͕ී௨ • MVCʹݶΒͣɺͲͷΞʔΩςΫνϟͰ͋ͬͯ ΋ಉ͡

  17. ௨஌Λ͠Α͏

  18. ཧ૝

  19. ௨஌͢ΔଆΠϝʔδ .notifyΛݺͿ͚ͩ

  20. ௨஌Λड͚औΔଆΠϝʔδ ͍͍ײ͡ʹDelegateͰड͚औΕΔ

  21. DelegateΛҾճ͢ඞཁ͕ͳ͍ DelegateύλʔϯͷΑ͏ͳ Πϝʔδ

  22. ͦ͜Ͱ Responder Chain

  23. = UIResponderͷ࿈ͳΓ

  24. None
  25. UIResponder • UIReponder = ϢʔβͷೖྗΛर͑Δ΍ͭ • ͋ΔsubviewͰΠϕϯτΛर͏ͱॲཧͰ͖Δͱ ͜Ζ·Ͱ࣍ʑʹॲཧΛճ͍ͯ͘͠ • self.next

    Ͱ࣍ͷResponder͕औΕΔ = Responder Chain
  26. None
  27. UIResponder • ResponderChain্ʹ͸౰વViewController΋ ͍Δʂ • DelegateΛҾ͖ճ͢·Ͱ΋ͳ͘ɺ͢Ͱʹͭͳ ͕͍ͬͯΔ • ͜Εʹ৐͔ͬΕ͹͍͍ײ͡ʹViewControllerʹ ʮ௨஌ʯͰ͖ͦ͏ʂ

  28. ͳΜ͔࢖͑ͦ͏

  29. Ͳ͏΍Δ͔ʁ

  30. ActionΛఆٛ͢Δ

  31. DelegateΛఆٛ͢Δ

  32. ViewEventΛఆٛ͢Δ ୭͕ϋϯυϧ͢Δ͔ͱɺ Ͳ͏σΟεύον͢Δ͔ΛܾΊΔɻ

  33. ViewEventΛఆٛ͢Δ

  34. UIResponderΛ֦ு͢Δ Responder ChainΛḷͬͯɺ ΠϕϯτΛϋϯυϧͰ͖Δ΍ͭΛݟ͚ͭΔ

  35. ׬੒ʂ

  36. ௨஌͢ΔଆΠϝʔδ .notifyΛݺͿ͚ͩ

  37. ௨஌Λड͚औΔଆΠϝʔδ ͍͍ײ͡ʹDelegateͰड͚औΕΔ

  38. ཧ૝ͷੈք͕࣮ݱͨ͠

  39. ྑ͍఺ • DelegateΛViewͷਂ͍֊૚·ͰҾճ͢ඞཁ͕ ͳ͘ͳͬͨ • Viewͷ֊૚͕มԽͨ͠ͱͯ͠΋ɺίʔυͷม ߋ͕ෆཁɻViewͷมߋʹڧ͍ɻ

  40. มΘΒͳ͍఺ • ͋ΔΠϕϯτΛड͚औΔͨΊͷprotocol࣮૷ ͠๨ΕΛίϯύΠϧ࣌ʹ͸ݕग़Ͱ͖ͳ͍ • ͜Ε͸Delegateઃఆ͠๨ΕͰ΋ಉ͡ • ࣮ࡍʹಈ͔͢ or ςετͰΧόʔ

  41. RxCocoa΁ͷԠ༻

  42. RxCocoa + Responder Chain • RxΛ࢖͍ͬͯͯ΋ಉ͡໰୊͕ى͜Δ • RxDataSourcesΛ࢖͍ͬͯͯ΋ɺCellͷதͷΠ ϕϯτ͸र͑ͳ͍ •

    Responder Chainʹྲྀͯ͠͠·͓͏
  43. ukitaka/RxResponderChain

  44. ࢖͍ํ

  45. ࡶʹResponder Chainʹྲྀ͢ Ϙλϯ͕λοϓ͞ΕͨΒ

  46. ࡶʹResponder Chainʹྲྀ͢ ద੾ͳܕʹม׵ͯ͠

  47. ࡶʹResponder Chainʹྲྀ͢ Responder Chainʹྲྀ͢

  48. ࡶʹVCͰड͚औΔ ViewControllerͰ ܕΛࢦఆͯ͠ड͚औΔ

  49. গ͚࣮ͩ͠૷ΛΈΔ

  50. ࣮૷ͷཪଆ ࠇຐज़ʹΑ֤ͬͯUIResponderΦϒδΣΫτʹ PublishSubjectΛ࣋ͨͤΔ

  51. ࣮૷ͷཪଆ self.rx.responderChain Λੜ΍͢

  52. ࣮૷ͷཪଆ ͜ͷΦϒδΣΫτ͸ObserverType

  53. ࣮૷ͷཪଆ ઒ʹEvent͕ྲྀΕ͖ͯͨΒ ResponderChainΛḷͬͯ

  54. ࣮૷ͷཪଆ ͖ͬ͞ੜ΍ͨ͠PublishSubjectʹ ΠϕϯτΛྲྀ͢

  55. ࣮૷ͷཪଆ ड͚औΔͱ͖͸ܕͰfilter

  56. ·ͱΊ

  57. ResponderChain • View → ViewController͸Responder Chainܨ ͕͍ͬͯΔ • ௨஌ʹ࢖͑Δ /

    ָʹॻ͚Δ / มߋʹڧ͍
  58. ͓ΘΓ