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

いまさらですがRxSwiftつかってみました

 いまさらですがRxSwiftつかってみました

https://potatotips.connpass.com/event/50155/ で発表した発表資料です。
アプリに実際にRxSwiftを使ってみた事をまとめました。

Tsuyoshi Yonemoto

March 22, 2017
Tweet

More Decks by Tsuyoshi Yonemoto

Other Decks in Programming

Transcript

  1. ͍·͞ΒͰ͕͢
    RxSwift͔ͭͬͯΈ·ͨ͠
    potatotips #38
    @yoneapp
    Tsuyoshi Yonemoto

    View full-size slide

  2. @yoneapp
    • ̎̌̍̎೥ɿελʔτΞοϓͷڞಉ૑ۀऀ
    • ̎̌̍̑೥ɿiOS & RailsϑϦʔϥϯε

    View full-size slide

  3. ΞϓϦ͕ग़·ͨ͠ʂʢ̍ʣ

    View full-size slide

  4. ΞϓϦ͕ग़·ͨ͠ʂʢ̎ʣ

    View full-size slide

  5. RxSwiftΛ࢖ͬͯΈ·ͨ͠

    View full-size slide

  6. PRESS BLOGͰͷࣄྫ

    View full-size slide

  7. PRESSͷॳճىಈ

    View full-size slide

  8. PUSH௨஌τʔΫϯͷڞ༗
    • ΩʔΛૹΔʹ͸ϩάΠϯೝূ৘ใ͕ඞཁ
    • PUSH௨஌τʔΫϯͷऔಘλΠϛϯά
    • ॳճঝೝ࣌
    • ઃఆ͔Βঝೝ͞Ε͔ͯΒΞΫςΟϒ
    • γεςϜతʹมߋʁ
    • ผΞΧ΢ϯτͰϩάΠϯ͞ΕͨΒͲ͏͢Δ

    View full-size slide

  9. ෳࡶͩͳʔ

    View full-size slide

  10. RxSwiftΛ࢖ͬͯΈΑ͏

    View full-size slide

  11. ࣮ࡍͷίʔυ
    let sessionId = Session.shared.sessionId.asObservable().unwrap()
    let pushToken = pushTokenObservable.unwrap()
    Observable.combineLatest(sessionId, pushToken) {
    PushTokenUpdateRequest(sessionId:$0, pushToken: $1)
    }
    .subscribe(onNext: { _ = $0.post() })
    .addDisposableTo(disposeBag)
    ※ unwrap(RxSwiftExt)͸nilΛফ͢

    View full-size slide

  12. ࣮ࡍͷίʔυ
    OneSignal.idsAvailable { (playerId, pushToken) in
    self.pushTokenObservable.onNext(pushToken)
    }

    View full-size slide

  13. ࣮ࡍͷίʔυ
    class Session {
    static let shared = Session()
    var sessionId: Variable
    }

    View full-size slide

  14. RxSwift
    ঢ়ଶΛม਺ͱͯ͠ఆٛͰ͖Δͱཧղͨ͠

    View full-size slide

  15. ෳࡶͳ໰୊ΛղܾͰ͖ͨ
    let sessionId = Session.shared.sessionId.asObservable().unwrap()
    let pushToken = pushTokenObservable.unwrap()
    Observable.combineLatest(sessionId, pushToken) {
    PushTokenUpdateRequest(sessionId:$0, pushToken: $1)
    }
    .subscribe(onNext: { _ = $0.post() })
    .addDisposableTo(disposeBag)
    ※ unwrap(RxSwiftExt)͸nilΛফ͢

    View full-size slide

  16. ࣮૷ͯ͠Έͯ…

    View full-size slide

  17. pausableBuffered
    http://rxmarbles.com/#pausableBuffered

    View full-size slide

  18. RxSwiftʹ͸ແ͍

    View full-size slide

  19. ແ͍΋ͷ΋͋Δ
    http://reactivex.io/documentation/operators/backpressure.html

    View full-size slide

  20. Observable.combineLatest
    http://rxmarbles.com/#combineLatest

    View full-size slide

  21. unwrap(RxSwiftExt)
    https://github.com/RxSwiftCommunity/RxSwiftExt#unwrap

    View full-size slide

  22. ΋ͬͱRxSwiftΛ࢖͍͜ͳ͠
    ͯૉఢͳΞϓϦΛ࡞Γ·͢

    View full-size slide