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

ReactiveCocoaでのフロー制御の例

 ReactiveCocoaでのフロー制御の例

ReactiveCocoa 2.xを使ったサンプルアプリでのフロー制御例を紹介します。

53e469a19bcb4584c87789d237128ca0?s=128

matuyuji

July 26, 2014
Tweet

Transcript

  1. 3FBDUJWF$PDPB Ͱͷϑϩʔ੍ޚͷྫ @matuyuji ! ReactiveCocoaษڧձؔ੢ 2014.7.24

  2. !NBUVZVKJ w TBGYEFWCMPHTQPUKQ w &NBDT࢖͍

  3. 3FBDUJWF$PDPB࢖ͬͯ ΞϓϦͭͬͯ͘Έͨ w .JP%BTICPBSE w HJUIVCDPNTBGY.JP%BTICPBSE

  4. **+.JPΈ͓ΆΜ"1* w ߴ଎௨৴༻Ϋʔϙϯͷ0/0'' w Ϋʔϙϯ࢒ྔɺ೔ʑͷར༻ྔ w 3&45"1* w 0"VUI +40/

  5. ΍Δ͜ͱ w +40/औಘ w IUUQTBQJJJKNJPKQNPCJMFEWDPVQPO w IUUQTBQJJJKNJPKQNPCJMFEWMPHQBDLFU w +40/σʔλͷϚʔδ w

    0"VUIʹΑΔೝূ τʔΫϯ࠶औಘ
  6. ΍͍ͬͯΔ͜ͱ w +40/औಘ  " IUUQTBQJJJKNJPKQNPCJMFEWDPVQPO  # IUUQTBQJJJKNJPKQNPCJMFEWMPHQBDLFU w

    +40/σʔλͷϚʔδ w 0"VUIʹΑΔೝূ τʔΫϯ࠶औಘ → AFNetworking-RACExtensionsͷ rac_startJSONRequestOperationWithRequest: → concat:ͰͱΓ͚͋͑ͣͬͭ͘Δɻ map:಺ͰMantle࢖͔ͬͯΒϚʔδ → ΞΫηετʔΫϯΛnilʹͯ͠࠶࣮ߦ
  7. +40/σʔλͷऔಘ (A) (B) rac_startJSONRequest…: defer defer rac_startJSONRequest…: concat: collect NSDict

    NSDict NSDict × 2 NSArray → AFNetworking-RACExtensionsͷ rac_startJSONRequestOperationWithRequest:
  8. γάφϧͰͷΠϕϯτ next completed error id NSError

  9. "DPODBU# next completed error NSError id next id completed error

    NSError
  10. +40/σʔλͷऔಘ (A) (B) rac_startJSONRequest…: defer defer rac_startJSONRequest…: concat: collect NSDict

    NSDict NSDict × 2 NSArray
  11. +40/σʔλͷऔಘ - (RACSignal*)loadInformationSignal { RACSignal* coupon = [RACSignal defer:^RACSignal* {

    return [self.restHelper getCoupon]; }]; ! RACSignal* packet = [RACSignal defer:^RACSignal* { return [self.restHelper getPacket]; }]; ! RACSignal* sig = [[coupon concat:packet] collect]; return sig; } தͰrac_startJSONRequestOperationWithRequest:ΛݺͿ
  12. 0"VUIͷೝূ - (RACSignal*)loadInformationSignal { RACSignal* coupon = [RACSignal defer:^RACSignal* {

    return [self.restHelper getCoupon]; }]; ! RACSignal* packet = [RACSignal defer:^RACSignal* { return [self.restHelper getPacket]; }]; ! RACSignal* sig = [[coupon concat:packet] collect]; return self.restHelper.accessToken ? sig : [[[self.restHelper authorize] catch:self.errorBlock] concat:sig]; } complete͔error͚ͩฦ͢γάφϧ
  13. 0"VUIͷೝূ (A) (B) rac_start…: defer defer concat: collect NSDict NSDict

    NSDict × 2 NSArray rac_start…: concat: authorize catch: NSArray
  14. MPBE*OGPSNBUJPO4JHOBM (A) (B) rac_start…: defer defer concat: collect NSDict NSDict

    NSDict × 2 NSArray rac_start…: concat: authorize catch: NSArray
  15. MPBE*OGPSNBUJPO4JHOBM - (RACSignal*)loadInformationSignal { RACSignal* coupon = [RACSignal defer:^RACSignal* {

    return [self.restHelper getCoupon]; }]; ! RACSignal* packet = [RACSignal defer:^RACSignal* { return [self.restHelper getPacket]; }]; ! RACSignal* sig = [[coupon concat:packet] collect]; return self.restHelper.accessToken ? sig : [[[self.restHelper authorize] catch:self.errorBlock] concat:sig]; }
  16. ϚʔδͱτʔΫϯ࠶औಘ [[[self loadInformationSignal] catch: ^RACSignal *(NSError *error) { if (/*ΞΫηετʔΫϯ͕ແޮ*/)

    { self.restHelper.accessToken = nil; return [self loadInformationSignal]; } return [RACSignal empty]; //ଞͷΤϥʔ͸͖͋ΒΊΔ }] map:^(NSArray* array) { // MantleͰΦϒδΣΫτ࡞੒͔ͯ͠ΒɺσʔλΛ·ͱΊΔ }];
  17. τʔΫϯ࠶औಘ (A) (B) rac_start…: defer defer concat: collect NSDict NSDict

    NSDict × 2 NSArray rac_start…: concat: authorize catch: NSArray
  18. ΍ͬͨ͜ͱ w +40/औಘ  " IUUQTBQJJJKNJPKQNPCJMFEWDPVQPO  # IUUQTBQJJJKNJPKQNPCJMFEWMPHQBDLFU w

    +40/σʔλͷϚʔδ w 0"VUIʹΑΔೝূ τʔΫϯ࠶औಘ → AFNetworking-RACExtensionsͷ rac_startJSONRequestOperationWithRequest: → concat:ͰͱΓ͚͋͑ͣͬͭ͘Δɻ map:಺ͰMantle࢖͔ͬͯΒϚʔδ → ΞΫηετʔΫϯΛnilʹͯ͠࠶࣮ߦ
  19. ࢖ͬͨϥΠϒϥϦ w 3FBDUJWF$PDPB w "'/FUXPSLJOH3"$&YUFOTJPOT w 6OEFSTDPSFN w .BOUMF w

    58.FTTBHF#BS.BOBHFS w 75"DLOPXMFEHFNFOUT7JFX$POUSPMMFS w 9:1JF$IBSU w J041MPU
  20. ؔ࿈৘ใ w 3FBDUJWF$PDPBؔ࿈ϦϯΫͷ·ͱΊ w TBGYEFWCMPHTQPUKQSFBDUJWFDPDPBIUNM