Macアプリを作って憶えるRxSwift

7d1521d950d9bc5697868830cb04ff2f?s=47 yimajo
April 14, 2016

 Macアプリを作って憶えるRxSwift

RxSwift勉強会発表資料です
http://connpass.com/event/27933/

7d1521d950d9bc5697868830cb04ff2f?s=128

yimajo

April 14, 2016
Tweet

Transcript

  1. .BDΞϓϦΛ࡞ͬͯ Ա͑Δ3Y4XJGU 3Y4XJGUษڧձ4BOTBO  !ZJNBKP

  2. ࣗݾ঺հ w !ZJNBKP w ਓͰגࣜձࣾΩϡϦΦγςΟ ιϑτ΢ΣΞΛ΍͍ͬͯ·͢ w TUBSH[SOFUͱ͍͏αΠτΛӡ Ӧ͍ͯ͠·͢

  3. None
  4. 3FBDUJWF4XJGU.FFUVQ ൃදͷ൒෼͘Β͍ͷਓ͕ .77.ύλʔϯ΍qVYʹ͍ͭͯ࿩ͯͨ͠ͷ͸ ͦ͜ʹڵຯ͕͋Δ͔Βʜ ͦ͏͍͑͹ࡢ೔ʹ͜Μͳͷ͋ͬͨΑͶ

  5. ࿩͢͜ͱ w 3Y4XJGUͰ௒࣮༻తͳ.BDΞϓϦΛ࡞ͬͨͷͰॱ ংཱͯͯͦͷ࿩Λ͠·͢ w .77.पลʹ͍ͭͯ΋࿩͠·͢

  6. લఏ

  7. w ࠷ۙ3Y4XJGUΛ࢝ΊͨʮʹΘ͔੎ʯͰ͍͟͝ ·͢

  8. w ϦΞΫςΟϒϓϩάϥϛϯάʹ͍ͭͯ஌Βͳ͍ ਓ΋෼͔Δײ͡ͷઆ໌Λ͠·͢

  9. w ؒҧ͍΋͋Δͱࢥ͏ͷͰಥͬࠐΜͰ΋Βͬͨ΄ ͏͕ಘΔ΋ͷ͕ଟ͍Ͱ͢

  10. w 3Y$PDPB $PDPB&YUFOTJPOT ͷ࿩΋3Y4XJGUͱ ͯ͠࿩͠·͢

  11. 3Y4XJGUͰ࡞ͬͨ.BD ΞϓϦͱ͸ʁ

  12. %&.0 3Y4XJGU@4BOTBOͰπΠʔτ͢Δͱಈ͍͍ͯΔ͸ͣ ಈ͍ͯͳ͔ͬͨΒଈൃදऴྃ

  13. εΫϦʔϯγϣοτ

  14. ͜ͷΞϓϦͷཁ݅ͱ 3Y4XJGUΛ࢖࣮ͬͨ૷

  15. ཁ݅ ද͍ࣔͨ͠σΟεϓϨΠΛࣗಈݕग़ ͯ͠બͿ σΟεϓϨΠݕ஌ͰSY@OPUJpDBUJPO

  16. SY@OPUJpDBUJPO w /4/PUJpDBUJPOͷSY@OPUJpDBUJPO࢖͏ͱΫϩʔ δϟʹ௨஌࣌Λड͚ͨࡍͷॲཧॻ͚Δ w EJTQPTF#BHΛ࢖͑Δ NSNotificationCenter.defaultCenter() .rx_notification(NSApplicationDidChangeScreenParametersNotification) .subscribeNext {

    [unowned self] _ in self.tableView.reloadData() } .addDisposableTo(disposeBag)
  17. ཁ݅ ݕࡧ͍ͨ͠ϋογϡλάΛೖྗͯ͠ ࣮ߦ SY@UFYU΍SY@UBQ

  18. SY@UFYU w 3Y4XJGUͷجૅతͳ࢖͍ํ௨ΓWBMJEBUF w ݕࡧจࣈ͕͋Ε͹ݕࡧϘλϯΛ׆ੑԽ let searchValid = searchField.rx_text .map{

    text -> Bool in 0 < text.characters.count } searchValid .bindTo(searchButton.rx_enabled) .addDisposableTo(disposeBag)
  19. SY@UBQ w 3Y4XJGUͷجૅతͳ࢖͍ํ௨ΓTVCTDSJCF/FYU w ͚Ͳ࣮͸େͨ͜͠ͱ͠ͳ͍ͳΒ!*#"DUJPOͰ͍͍ʢͳΜͰ΋SYͱ͍ ͏ͷ͸όϥϯε͕ѱ͍൑அͩͱࢥ͏ʣ searchButton.rx_tap .subscribeNext { [unowned

    self] in // ͜͜ʹtap͞Εͨॲཧॻ͘ } .addDisposableTo(disposeBag)
  20. ཁ݅ πΠʔτΛӈ͔Βࠨʹ "1*ͷ݁ՌΛ1VCMJTI4VCKFDU

  21. 5XJUUFS"1*ͷ݁ՌΛ1VCMJTI4VCKFDU w πΠʔτ͕ݟ͔ͭͬͨΒPO/FYU w "1*ͷΤϥʔͳΒPO&SSPS w ͦΕΛ4VCTDSJCFͯ͠7JFXΛ࡞Δ

  22. ཁ݅ ΞϓϦͷঢ়ଶ΋πΠʔτͷΑ͏ʹը ໘ʹදࣔͯ͋͛͠Δ 0CTFSWBCMFΛJOUFSWBMͰఆظతʹ

  23. JOUFSWBMͰఆظతʹ0CTFSWBCMFͳ΋ͷΛ w ඵ͝ͱʹ"OOPVODF͍ͬͯ͏4USVDUΛ࡞Δ return Observable<Int> .interval(60.0, scheduler: MainScheduler.instance) .map {

    _ in return Announce(id: NSUUID().UUIDString, text: announceText) }
  24. ͭͷετϦʔϜΛNFSHF͢Δ ཁ݅ ʮπΠʔτʯ΋ʮΞϓϦ͔Βͷ৘ใ௨஌ʯ΋ σΟεϓϨΠӈ͔Βࠨʹྲྀ͢ͷͰҰͭͷ ετϦʔϜʹͳͬͯΕ͹͍͍

  25. NFSHF 5XJUUFS"1*઒ 1VCMJTI4VCKFDU$PNNFOU5ZQF ΞϓϦͷϝοηʔδ઒ 0CTFSWBCMF$PNNFOU5ZQF $PNNFOU5ZQFͱ͍͏ϓϩτίϧͭ͘Δ &MFNFOU͕ಉ͡͡Όͳ͍ͱNFSHFͰ͖ͳ͍ͷͰ

  26. // Commentϓϩτίϧ protocol CommentType { func type() -> Comment func

    identifier() -> String func message() -> String func imageURL() -> NSURL? } enum Comment { case Tweet case Announce } // TweetΛJSON͔ΒΤϯςΟςΟԽ // HimotokiͷDecodableΛܧঝ struct Tweet: Decodable { //…লུ… } // ϓϩτίϧͷ࣮૷෦ extension Tweet: CommentType { //…লུ… } // ΞϓϦ͔Βͷϝοηʔδ৘ใ struct Announce: CommentType { //…লུ… }
  27. ౧ϓϩτίϧʹै͍ͬͯ͑͞Ε͹͍͍

  28. NFSHFͱ͔ ετϦʔϜ߹੒ͷྑ͞ʹ͍ͭͯ ΋͏গ͠ ʢ௒ࢲݟʣ

  29. ϝιουGͷݺͼग़͠ ϝιουGͷݺͼग़͠ ϝιουGͷݺͼग़͠ ϝιουGͷݺͼग़͠ ॲཧ" ॲཧ#ͱ৚݅ ௨஌$ ॲཧ"ͷετϦʔϜ ॲཧ#ͷετϦʔϜ ௨஌$ͷετϦʔϜ

    ϦΞΫςΟϒ ϓϩάϥϛϯά෩ͳ ϝιουΛ ౎౓ݺͼग़͢ͱ
  30. Ͱ ͜ͷ.BDΞϓϦ͍ͭ ϦϦʔε͢ΔΜͰ͢ʁ

  31. ʜϦϦʔε͠ͳ͍ ʢ.BDͷσϕϩούϥΠηϯε͸ ࣋ͬͯͳ͍͠ʣ

  32. ҆৺ͯ͠Լ͍͞

  33. ίʔυ͸ެ։͞Ε͍ͯ·͢ IUUQTHJUIVCDPNZJNBKP.FFUVQ5XFFU ˒Λ͚ͭͯ๨Εͳ͍Α͏ʹ͓ͯ͘͠ͱྑ͍Ͱ͢Ͷ

  34. ࣍ʹ ެ։͞ΕͨίʔυΛར༻͢ΔͨΊͷ࿩ IUUQTHJUIVCDPNZJNBKP.FFUVQ5XFFU

  35. 5XJUUFSͷ"1*,FZͱ 4FDSFU͕ඞཁͰ͢ IUUQTHJUIVCDPNZJNBKP.FFUVQ5XFFU

  36. Ϋϥεߏ੒͸ʁ 3Y4XJGU࢖ͬͨ.77.ͳͷʁ

  37. 5XJUUFSͷ,FZೖྗ͸.77. "VUI 7JFX.PEFM w $POTVNFS,FZͱ 4FDSFUΛWBMJEBUF͢Δ w ໰୊ͳͦ͞͏ͳΒϒϥ ΢βىಈ͢Δ "VUI

    7JFX$POUSPMMFS w $POTVNFS,FZͱ 4FDSFUΛೖྗͤ͞ w "VUI7JFX.PEFMʹ 0"VUI4XJGU w 0"6UIͷ ॺ໊Λ࡞੒ Ͱ͖Δ
  38. 5XFFU4FBSDI 7JFX$POUSPMMFS $PNNFOU'MPX 1SFTFOUFS w 6*͔ΒͷΠϕϯτΛॲཧ w ݕࡧ͢ΔจݴΛೖྗ w දࣔ͢Δը໘ΛબͿ

    w 5XFFU4USFBN"1*ͷ 6TF$BTFΛݺͼग़͢ w "OOPVODF6TF$BTFΛݺ ͼग़͢ w NFSHF͠TVCTDSJCF w 7JFXʹͯ͠ը໘্ʹྲྀ͢ 5XJUUFS4USFBN"1* 6TF$BTF w 5XJUUFS4USFBN"1*Λݺ ͼग़͠1VCMJTI4VCKFDU "OOPVODF 6TF$BTF w ΞϓϦ͕ࣗಈͰදࣔ͢Δ ίϝϯτΛ0CTFSWBCMF ʹ 1SFTFOUBUJPO૚ %PNBJO૚ *OGSB૚ 5XJUUFS"1* )JNPUPLJ 5XFFUදࣔ͸ϨΠϠʔυ෩ΞʔΩςΫνϟ ࢀߟ IUUQTUFDISFDSVJUNQDPKQNPCJMFQPTU w )JNPUPLJ͸͍͍ͧ w 4USFBN"1* Λݺͼग़ͤΔ
  39. 8IZ  ϨΠϠʔυ෩ΞʔΩςΫνϟ w ΋͏.PEFMͱ͍͏༻ޠ࢖͏ͷ΍Ί·ͤΜʁ w ௕͘ͳΔͷͰ࠙਌ձͰ࿩͠·͠ΐ͏

  40. ·ͱΊ

  41. खΛಈ͔͞ͳ͍ͱ3Y4XJGUΛशಘ͢Δͷ͸ ೉͍͠ ʮNFSHFͬͯҙຯෆ໌͚ͩͬͨͲ͜͜Ͱ࢖͏ͷ͔ʯ

  42. ͔͠͠࢓ࣄͰѻ͍ͬͯΔϓϩμΫγϣϯʹ ͍͖ͳΓೖΕΔͷ΋೉͍͠ 3YʹϩοΫΠϯͯ͠͠·͏ϦεΫ

  43. 3Y4XJGU࢖ͬͨ J1IPOFΞϓϦΛ࡞Ζ͏ͱࢥͬͯ΋ཉ͍͠΋ͷ ͸͢Ͱʹ͋ͬͨΓ͢Δ

  44. ͩͬͨΒ .BDΞϓϦ࡞Γ·͠ΐ͏ .BD࢖ͬͯͯෆศͩͱࢥ͏Α͏ͳ͜ͱ͋Δͱ ࢥ͏

  45. ࡞Γ͍ͨ.BDΞϓϦ͕ͳ͍ ˣ !ZJNBKP͕3Y4XJGUؚΉ ٕज़ΞυόΠε੥͚ෛ͍·͢Αʂʂ ͝૬ஊԼ͍͞

  46. ͓ΘΓ ܁Γฦ͠ʹͳΓ·͕͢ ˒Λ͚ͭͯ๨Εͳ͍Α͏ʹ͓͖ͯ͠ Ջͳ࣌ʹ1VMM3FRVFTU͘ΕΔͱخ͍͠Ͱ͢ IUUQTHJUIVCDPNZJNBKP.FFUVQ5XFFU