ゆるやかなReactiveCocoaの導入

6139fd48daa26e786794598c4a6b546a?s=47 ninjinkun
August 03, 2014

 ゆるやかなReactiveCocoaの導入

Fablic社でのReactiveCocoaの(ゆるい)導入事例

6139fd48daa26e786794598c4a6b546a?s=128

ninjinkun

August 03, 2014
Tweet

Transcript

  1. ΏΔ΍͔ͳ 3FBDUJWF$PDPBͷಋೖ OJOKJOLVO

  2. ΞδΣϯμ w ͳͥࠓ3FBDUJWF$PDPB 3"$ ͔ w 3FBDUJWF$PDPBͷஈ֊తͳ࠾༻ w .77.΁ͷ؇΍͔ͳҠߦ

  3. ஫ҙ w ษڧ͠ͳ͕Βࢿྉ࡞͍ͬͯ·͢ w ݴ༿ͷఆٛ΍࢖͍ํ͕ਖ਼͘͠ͳ͍Մೳੑ͕͋Γ·͢

  4. ͳͥࠓ3FBDUJWF$PDPB͔ w ΞϓϦͷෳࡶԽ w 8FCαʔϏε࿈ܞΞϓϦͷ૿Ճ w ඇಉظॲཧͷଟ༻

  5. ͳͥࠓ3FBDUJWF$PDPB͔ w ΞϓϦ͕ඇৗʹଟ͘ͷzঢ়ଶzͱzඇಉظॲཧzΛ࣋ͬ ͍ͯΔ w ଟ਺ͷ"1*ͱඇಉظʹ௨৴͠ɺঢ়ଶΛద੾ʹߋ৽ ͠ɺϢʔβʔʹදࣔ͢Δ

  6. ͳͥࠓ3FBDUJWF$PDPB͔ w 'SJMͷ-JLF "1*ίʔϧ ঎඼Ϟσϧͷ-JLF  ὑΞΠίϯ൓స ͍͍Ͷ਺ͷߋ৽ -JLFͷߋ৽Λ௨஌ $FMMΛϦϩʔυ

    ঎඼.PEFMΛ౉ͯ͠ ৄࡉϏϡʔΛදࣔ ˞σʔλ͸։ൃػͷ΋ͷͰ͢
  7. ͳͥࠓ3FBDUJWF$PDPB͔ 

  8. ͳͥࠓ3FBDUJWF$PDPB͔ w .PEFMͷߋ৽ɺ௨஌ɺ7JFXͷߋ৽ w EFMFHBUFϝιουPS/4/PUJpDBUJPO$FOUFS w ίϝϯτɺϢʔβʔͷϑΥϩʔͳͲ΋ಉ͡ w खͰঢ়ଶΛಉظ͢ΔϝιουΛॻ͖ଓ͚ΔͷʹݶքΛײ͡Δ w

    ΈΜͳ͕Μ͹ͬͯ΍ͬͯΔ͚Ͳ w ঢ়ଶͷ؅ཧͱඇಉظॲཧΛந৅Խ͍ͨ͠
  9. ؔ਺ܕϦΞΫςΟϒϓϩάϥϛϯά '31 w l'31JTQSPHSBNNJOHXJUIBTZODISPOPVTEBUB TUSFBNTz w 4USFBN w ϢʔβʔͷΫϦοΫ 5XJUUFSͷGFFE

    FUDʜ
  10. ؔ਺ܕϦΞΫςΟϒϓϩάϥϛϯά '31 w ؔ਺ܕݴޠͷύϥμΠϜ͔Β༝དྷ w .JDSPTPGU͕/FUͰ(6*ք۾ʹ΋޿Ίͨ w ༷ʑͳ࣮૷͕͋Δ w 3FBDUJWF

    (SBQFGSVJU :BNQB BLLB w 3Y&YUFOUJPOT 3"$ 3Y+BWB 3Y+4 SFBDU
  11. '31ͷಛ௃ w 5IF3FBDUJWF.BOJGFTUPΑΓ w &WFOU%SJWFOΠϕϯτۦಈ w 4DBMBCMF֦ுੑ w 3FTJMJFOUো֐΁ͷ଱ੑ w

    3FTQPOTJWFԠ౴ੑ
  12. '31ͷ༻్ w αʔόʔͰ΋ΫϥΠΞϯτͰ΋࢖͑Δ֓೦ w ࣗ෼͕ࢥ͍ͭ͘'31ͷ༻్ w αʔόʔ w νϟοτɺಈը഑৴ɺΦϯϥΠϯήʔϜͳͲԠ౴ੑ͕ٻ ΊΒΕΔ΋ͷ

    w ΫϥΠΞϯτ w 4/4ɺνϟοτͳͲ"1*Λଟ਺ίʔϧ͢ΔΞϓϦɺήʔϜ
  13. εϚϑΥΞϓϦ͸ΠϕϯτͩΒ͚ w (6*ͷΠϕϯτ w λοϓɺδΣενϟ w ϋʔυ΢ΣΞͷΠϕϯτ w (14৘ใɺϞʔγϣϯ w

    ௨৴ͷΠϕϯτ w "1*ίʔϧͱϨεϙϯεड৴ɺΤϥʔॲཧ
  14. εϚϑΥΞϓϦͱ'31 w ΞϓϦ͕ංେԽͯ͘͠ΔͱΠϕϯτͩΒ͚ʹͳΔ w ಛʹ8FCαʔϏεͷΫϥΠΞϯτͰݦஶ w 8FCαʔϏε֤͕ࣾ'31Λར༻࢝͠Ί͍ͯΔ w (JUIVC /FUqJY

    αʔόʔ 'BDFCPPL +4  w $IBUXPSL 'SFFF 'BCMJD *ODSFNFOUT
  15. 3"$ͷஈ֊తͳ࠾༻

  16. 'BCMJDͷ3"$ར༻ϙϦγʔ w 3"$ʹϩοΫΠϯ͞ΕΔΑ͏ͳ࣮૷͸ආ͚Δ w 3"$ΦϒδΣΫτΛϞδϡʔϧؒͷΠϯλʔϑΣ Πεʹ࢖༻͠ͳ͍ w ·ͩͪΌΜͱ3"$ΛཧղͰ͖͍ͯͳ͍ͷͰʜ

  17. 3FBDUJWF$PDPBͷஈ֊తͳ࠾༻ w 'BCMJDͰͷ3"$ͷ༻్ w ςΩετͷ7BMJEBUJPO w %FMFHBUFϥούʔ w ,70ϥούʔ w

    .77.ͷͱ͜ΖͰޙड़
  18. ςΩετͷ7BMJEBUJPO w όϦσʔγϣϯͯ͠ϘλϯΛFOBCMFʹ͢Δ w 3"$ͷ3&"%.&ʹྫ͕͋ΔͷͰͱΓ͋͑ͣಋೖ ͢Δʹ͸͏͚ͬͯͭ w ྫ͑͹͜Ε͸ۜߦͷࢧళΛೖྗͤ͞Δίʔυ RAC(self.navigationItem.rightBarButtonItem, enabled)

    = [_branchCodeTextField.rac_textSignal map:^id(NSString *text) { return @(text && [ValidatioUtil isValidBranchCode:text]); }];
  19. EFMFHBUFϥούʔ w EFMFHBUFϝιουΛ࢖Θͣʹͦͷ৔ͰCMPDLΛ౉ͤ Δ w #MPDLT,JUͱಉ͡༻్ UIAlertView *alertView = [[UIAlertView

    alloc] initWith…]; [[alertView rac_buttonClickedSignal] subscribeNext:^(NSNumber *buttonIndex) { switch ([buttonIndex integerValue]) { case 1: do some thing… break; case 2: do something … break; default: break; } }]; [alertView show];
  20. .77.΁ͷ
 ؇΍͔ͳҠߦ

  21. .77.ͱ͸ w .PEFM7JFX7JFX.PEFM w 7JFX.PEFM w 7JFXΛඳը͢ΔͨΊͷঢ়ଶอ࣋ w 7JFXΠϕϯτͷ݁ՌΛ.PEFM΁఻ୡ 7JFX

    7JFX.PEFM .PEFM
  22. 3"$Ͱ.77. w 7JFX7JFX.PEFMؒΛCJOEJOH w 7JFX.PEFMͷߋ৽͸ࣗಈతʹ7JFXʹ൓ө 7JFX 7JFX.PEFM .PEFM 6*7JFX 6*7JFX$POUSPMMFS

    3"$ͰCJOEJOH RAC(self.detailMessageLabel, text) = [RACObserve(self, detailMessage) filter:^BOOL(NSString *message) { return message.length; }];
  23. ͳͥ.77.͕ඞཁ͔ w -JLFͷྫ ঎඼7JFX.PEFMͷ
 -JLF 7JFX.PEFMͷߋ৽Λݕ஌
 ࣗಈతʹ$FMMΛߋ৽ ঎඼7JFX.PEFMΛ
 ౉ͯ͠ৄࡉϏϡʔΛදࣔ

  24. ͳͥ.77.͕ඞཁ͔ w 4/4ΞϓϦͰ͸ঢ়ଶΛ7JFX$POUSPMMFSؒͰڞ༗͢ Δ͜ͱ͕ଟ͍ w -JLF਺ w ίϝϯτ਺ w ΤϯτϦ৘ใͷ௥Ճɺฤूɺ࡟আ

    w 7JFX.PEFMΛCJOE͢Ε͹7JFX͸ࣗಈߋ৽ʹ͍ͨ͠
  25. 3FBDUJWF$PDPBຊͷ.77. w 3"$7JFX.PEFMΛܧঝͯ͠7.Λ࣮૷ w )551ϦΫΤετͷ։࢝·Ͱ7.͕࣋ͭ w 7JFX$POUSPMMFSʹ3"$4JHOBMΛฦͯ͠ ॲཧͷ੒ޭɺࣦഊΛड͚ͱΔ w 3"$4JHOBMґଘͷઃܭʹͳΔͷͰࠓͷͱ

    ͜Ζෆ࠾༻
  26. ๻ͷߟ͑ΔΏΔ͍.77. w ͱʹ͔͘.VUBCMFͳ΋ͷ͸7.ʹूΊΔ w +40/͔Βੜ੒͞Εͨ/40CKFDU͸*NNVUBCMFʹ w 7.ʹର͢ΔϢχοτςετΛॻ͘ w 3"$͸CJOEͷΈʹ࢖͏ FLItem

    *item = self.items[indexPath.item]; ! __weak typeof(self) weakSelf = self; // ৄࡉͰLikeΛ֎ͨ͠ΒҰཡͰ΋Like͕֎ΕΔΑ͏ʹ͢Δ [RACObserve(item, liked) subscribeNext:^(id x) { [weakSelf.collectionView reloadItemsAtIndexPaths:@[indexPath]]; }];
  27. 'SJMͷ঎඼7. w ෳ਺ͷ+40/༝དྷ/40CKFDUΛ͍࣋ͬͯΔ w λΠϜϥΠϯͱৄࡉϏϡʔͷ"1*͝ͱʹऔΕΔ৘ใ ͷৄࡉ౓͕ҧ͏ͷͰɺ߹੒ͯ͠܅͚ͩͷ.PEFMΛ࡞ Δඞཁ͕͋Δ

  28. 'SJMͷ঎඼7. λΠϜϥΠϯ"1* ঎඼ ঎඼ৄࡉ"1* αΠζ ഑ૹྉ ഑ૹํ๏ ίϝϯτ ঎඼໊ ϒϥϯυ

    Ձ֨ ঎඼ ঎඼ αΠζ ഑ૹྉ ഑ૹํ๏ ίϝϯτ ঎඼໊ ϒϥϯυ Ձ֨ ঎඼7JFX.PEFM 
  29. 'SJMͷ঎඼7. w ঎඼7JFX.PEFMΛ3"$ͰCJOE w ঎඼7JFX.PEFMΛߋ৽͢Δ w 7JFXʹ͸ࣗಈతʹঢ়ଶ͕൓ө͞ΕΔ w ঎඼+40/ͷू໿ ঢ়ଶͷू໿


    7JFX΁ͷಉظ αΠζ ഑ૹྉ ഑ૹํ๏ ίϝϯτ ঎඼໊ ϒϥϯυ Ձ֨ ঎඼7JFX.PEFM
  30. '31ͷڭࡐ

  31. 5IFJOUSPEVDUJPOUP3FBDUJWF 1SPHSBNNJOHZPVWFCFFONJTTJOH w IUUQTHJTUHJUIVCDPNTUBMU[ FFCDBCDG w ϦΞΫςΟϒ·ͱΊ w ೖ໳ฤͱͯ͠Ұ൪ྑ͍ͱࢥ͏

  32. 1SJODJQMFTPG3FBDUJWF 1SPHSBNNJOH w $PVSTFSB w 4DBMBͱBLLBΛ࢖ͬͨ'31ͷߨٛ w .BSUJO0EFSTLZઌੜ͔Βश͑Δ w '31ͷجૅΛஸೡʹղઆ

    w ΫϥΠΞϯτΞϓϦͷ࿩͸ͳ͍ w 3"$Λ࢖͍͍͚ͨͩͳΒΦʔόʔεϖοΫ͔΋
  33. 3FBDUJWF1SPHSBNNJOHJOJ04 w 3FBDUJWF$PDPBͷຊ w ϖʔδ͘Β͍ w .77.ͷ΍Γํॻ͍ͯ͋Δ w 3"$ͷυΩϡϝϯτͰॆ෼આ͋Γ w

    ݸਓతʹ͸ಡΜͰଛ͸ͳ͔ͬͨ
  34. ·ͩΑ͘ཧղͰ͖ͯͳ͍͜ͱ w ଞͷ'31ϑϨʔϜϫʔΫͱ3"$ͷ༻ޠରԠ w $MBTTJD'31 4JHOBM'VODUJPO w Ξχϝʔγϣϯͱͷ૬ੑ͕ѱ͍આ

  35. ·ͱΊ w '31ͱεϚʔτϑΥϯΞϓϦͷؔ܎ʹ͍ͭͯઆ໌͠ ·ͨ͠ w 3FBDUJWF$PDPBͷஈ֊తͳ࠾༻ w 7BMJEBUJPOͰͷ࢖༻ɺEFMFHBUFϥούʔ w .77.΁ͷ؇΍͔ͳҠߦ

    w զʑ͸·ͩ3"$தಟͰ͸ͳ͍ʜ
  36. ࣭ٙԠ౴ w .77.ͷղऍ͕ҧ͏ͷͰ͸ͳ͍͔ɺωοτϫʔΫ ॲཧ·Ͱ7.ʹ࣋ͨͤΔํ͕ࣗવͩͱࢥ͏ w 7.ʹ࣋ͨͤͨํ͕ΑΓ៉ྷʹॻ͚Δͷ͸ཧղ͠ ͍ͯΔ͕ɺ7.ͷΠϯλʔϑΣΠεʹ3"$4JHOBM Λ࢖Θͳ͘ͳΒͳ͚Ε͹͍͚ͳ͘ͳΔͷͰɺࠓͷ ͱ͜Ζ΍͍ͬͯͳ͍