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

migrating-from-promise-to-reactive

 migrating-from-promise-to-reactive

Gotanda.mobile #2 in VASILY (https://gotandamb.connpass.com/event/50876/)

503b1ca28b167b0d94a5992aad1a57b1?s=128

horimislime

March 23, 2017
Tweet

Transcript

  1. Promise͔ΒReactive΁ͷҠߦΛ໛ࡧ͢Δ Gotanda.mobile #2 @horimislime 1

  2. self • @horimislime • גࣜձࣾτϨλ @ޒ൓ాTOC • ҿ৯ళ޲͚iPad୆ாΞϓϦΛ։ൃͯ͠·͢ 2

  3. ͓࿩ • PromiseͰඇಉظϓϩάϥϛϯά͍ͯ͠Δ/͠Α͏ͱ͍ͯ͠Δਓ ʹ΋ReactiveΛΦεεϝ͢Δ࿩ • ๭ࣾͷΞϓϦͰͷࣄྫΛఴ͑ͯ 3

  4. Objective-Cࢿ࢈ͷ͋ΔΞϓϦ • BoltsFrameworkʹΑΔPromise • APIClient͕BoltsͷTaskΛฦ͢ • ্Ґ૚Ͱ΋޿ൣғʹBoltsʹґଘ 4

  5. ͦͯ͠SwiftҠߦظ΁ • Bolts͸AnyObject͕ฦ͖ͬͯͯπϥ͍ • SwiftyͳPromiseͷඞཁੑ • ͦͷޙ৭ʑ͋ͬͯҎԼʹґଘ͍ͯ͠Δ • Bolts-Objc •

    SwiftTask • Bolts-Swift 5
  6. PromiseͰͷ՝୊ײ • ଟ͘ͷ΋ͷͰErrorͷܕࢦఆ͕Ͱ͖ͳ͍ࣄ΁ͷෆຬ • ϝϯςφϯε͕׆ൃͰͳ͍΋ͷ͕ग़͖ͯͭͭ͋Δ 6

  7. enum AppError: Error { case offline case network } get(userId:

    1234).then { user in ... }.catch { error in // ! switch error as! AppError { ... } } 7
  8. ɹɹɹ ݁Ռͷܕࢦఆ Errorͷܕࢦఆ Swift3 Bolts-Swift ✅ ❌ ✅ PromiseKit ✅

    ❌ ✅ SwiftTask ✅ ✅ ❌(branch༗) 8
  9. Reactiveͷػӡ • SwiftҠߦͱڞʹSwiftBondΛ࢖͍࢝Ίͯͨ • ReactiveKitͱ͍͏฼ମʹґଘ • PromiseͰ΍Γ͍ͨࣄ͸େମͰ͖Δ 9

  10. Promise෩ຯͳReactiveKit findPrinter() .flatMapLatesst { printer in return send(document, to: printer)

    }.flatMapLatest { result in return process(result) }.observe { event in switch event { case .completed: Progress.dismiss() case .failed(let error): switch error { case .network: Progress.showError("Network error!") ... } } } 10
  11. ϝϦοτ • ͦΜͳʹҧ࿨ײ΋ͳ͍͠ɺbinding͚ͩͰͳ͘ඇಉظॲཧָ͕ • طʹView bindingΛ࢖͍ͬͯΕ͹਌࿨ੑ˕ • ௕ظతͳϝϯςφϯε΁ͷظ଴ 11

  12. ಋೖͷোน • Reactiveͷֶशίετ΁ͷݒ೦ • ͜ͷ1೥͘Β͍ͰσϑΝΫτԽͨ͠ײ͕͋Δ • View Bindingʹ࢖͏ͳΒશମతʹReactiveԽͨ͠ํ͕౎߹ ͕ྑ͍͜ͱ΋ଟ͍ 12

  13. ߟ͓͑ͯ͘΂͖ࣄ • Promise / Rxؔ࿈͸ෳ਺ϨΠϠͰ࢖༻͕ͪ͠ • Լखʹબ୒͢Δͱ๲େͳҠߦίετͰࢮ͵ • ࠷΋কདྷੑΛߟྀ͢Δ΂͖ॴ 13

  14. ·ͱΊ • SwiftΛऔΓר͘Promiseࣄ৘ • Reactiveͷোน͸ݮͬͯΔ͠ಋೖͷνϟϯε ! • ٕͨͩ͠ज़બఆ͸৻ॏʹ 14