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

SWORD ART COMBINE

yimajo
October 25, 2020

SWORD ART COMBINE

この発表資料は『iOSアプリ開発のためのFunctional Architecture情報共有会』で発表した資料です。
https://connpass.com/event/192067/

# その他 引用元

The Composable Architecture
https://github.com/pointfreeco/swift-composable-architecture

combine-schedulers
https://github.com/pointfreeco/combine-schedulers

SAO
https://sao-alicization.net/

YouTube
https://www.youtube.com/user/eguri89

yimajo

October 25, 2020
Tweet

More Decks by yimajo

Other Decks in Programming

Transcript

  1. • લฤ: TCAͰ࢖ΘΕ͍ͯΔ pointfreeco/combine-schedulers • https://github.com/pointfreeco/combine-schedulers • RxSwiftͱͷൺֱ • ޙฤ:

    ͦ΋ͦ΋CombineͰͷSchedulerͷ໾ׂ΍ಈ࡞ • pointfreeco/combine-schedulers ͕Ͳ͏΍ͬͯΔͷ͔ ࠓ೔࿩͢͜ͱ
  2. ղ૾౓ͱ͍͏֓೦͕͋Δ • Ծ૝࣌ؒ = ݱ࣮࣌ؒ / ղ૾౓ • ۩ମྫʢղ૾౓Λ0.1ͱͨ͠৔߹ʣ •

    Ծ૝࣌ؒ10 = ݱ࣮࣌ؒ1ඵ / ղ૾౓0.1 • Ծ૝࣌ؒ3 = ݱ࣮࣌ؒ0.3 / ղ૾౓0.1 ςετΛ࣮ߦ͢ΔλΠϛϯάΛݱ࣮࣌ؒͰࢦఆ͢ΔͷͰ͸ͳ͘ɺ Ծ૝࣌ؒͰࢦఆ͢Δ͜ͱͰςετ࣮ߦΛݱ࣮࣌ؒʹґଘͤ͞ͳ͍Α͏ʹͰ͖͍ͯΔɻ
  3. -> هऀձݟ։͘ΜͳΒ಄֖։͍ͯAIͬͯূ໌ͯ͠ ͡Ό͋ͦͬͪ΋಄֖։͍ͯਓؒͬͯূ໌ͯ͠ <- ΞϯμʔϫʔϧυਓΛ <- ਓ޻෺ݺ͹ΘΓ͚ͯͬ͠Ͳ͞ʙ ͓લΒͷੈքͷͦͷ্ʹ͸ Կ΋ͳ͍ͱݴ͍੾ΕΔΜ͔ʁ ͓લΒͷ૑଄ओ͕͍ͯɺ͓લΒࣗମ

    ਓ޻తʹͭ͘ΒΕͨΜ͡Όͳ͍ͬͯ ͦ͏͍͏ͷূ໌Ͱ͖Μͷ͔ʙ SAO ݱ࣮ੈքͷهऀ SAO ݱ࣮ੈքʹϩϘମͰ࿈Εͯ͜ΒΕͨ ΞϯμʔϫʔϧυਓͷΞϦε͞Μ Ҿ༻: https://sao-alicization.net/
  4. -> هऀձݟ։͘ΜͳΒ಄֖։͍ͯAIͬͯূ໌ͯ͠ ͡Ό͋ͦͬͪ΋಄֖։͍ͯਓؒͬͯূ໌ͯ͠ <- ΞϯμʔϫʔϧυਓΛ <- ਓ޻෺ݺ͹ΘΓ͚ͯͬ͠Ͳ͞ʙ ͓લΒͷੈքͷͦͷ্ʹ͸ Կ΋ͳ͍ͱݴ͍੾ΕΔΜ͔ʁ ͓લΒͷ૑଄ओ͕͍ͯɺ͓લΒࣗମ

    ਓ޻తʹͭ͘ΒΕͨΜ͡Όͳ͍ͬͯ ͦ͏͍͏ͷূ໌Ͱ͖Μͷ͔ʙ SAO ݱ࣮ੈքͷهऀ SAO ݱ࣮ੈքʹϩϘମͰ࿈Εͯ͜ΒΕͨ ΞϯμʔϫʔϧυਓͷΞϦε͞Μ ΞϯμʔϫʔϧυͰ฻Β͢ੜ໋ମ͸ ࣗ෼͕ͨͪSAOݱ࣮ੈքਓʹΑͬͯਓ޻తʹ ͭ͘ΒΕͨͳΜͯࢥͬͯͳ͍Θ͚ Ҿ༻: https://sao-alicization.net/
  5. subscribe(on:)ͱreceive(on:) let cancellable = publisher .flatMap { … } .subscribe(on:

    DispatchQueue.global()) .map { String($0) } .receive(on: DispatchQueue.main) .sink { print($0) }
  6. subscribe(on:)ͱreceive(on:) let cancellable = publisher .flatMap { … } .subscribe(on:

    DispatchQueue.global()) .map { String($0) } .receive(on: DispatchQueue.main) .sink { print($0) }
  7. subscribe(on:)ͱreceive(on:) let cancellable = publisher .flatMap { … } .subscribe(on:

    DispatchQueue.global()) .map { String($0) } .receive(on: DispatchQueue.main) .sink { print($0) } subscribe(on:)Ͱࢦఆͨ͠εέδϡʔϥʹΑΓɺ UpstreamͱDownstreamεϨου͕੾ΓସΘΔ
  8. subscribe(on:)ͱreceive(on:) let cancellable = publisher .flatMap { … } .subscribe(on:

    DispatchQueue.global()) .map { String($0) } .receive(on: DispatchQueue.main) .sink { print($0) } subscribe(on:)Ͱࢦఆͨ͠εέδϡʔϥʹΑΓɺ UpstreamͱDownstreamεϨου͕੾ΓସΘΔ
  9. subscribe(on:)ͱreceive(on:) let cancellable = publisher .flatMap { … } .subscribe(on:

    DispatchQueue.global()) .map { String($0) } .receive(on: DispatchQueue.main) .sink { print($0) } subscribe(on:)Ͱࢦఆͨ͠εέδϡʔϥʹΑΓɺ UpstreamͱDownstreamεϨου͕੾ΓସΘΔ
  10. subscribe(on:)ͱreceive(on:) let cancellable = publisher .flatMap { … } .subscribe(on:

    DispatchQueue.global()) .map { String($0) } .receive(on: DispatchQueue.main) .sink { print($0) } subscribe(on:)Ͱࢦఆͨ͠εέδϡʔϥʹΑΓɺ UpstreamͱDownstreamεϨου͕੾ΓସΘΔ receive(on:)Ͱࢦఆͨ͠εέδϡʔϥʹΑΓɺ DownstreamͷεϨου͕੾ΓସΘΔ
  11. subscribe(on:)ͱreceive(on:) let cancellable = publisher .flatMap { … } .subscribe(on:

    DispatchQueue.global()) .map { String($0) } .receive(on: DispatchQueue.main) .sink { print($0) } subscribe(on:)Ͱࢦఆͨ͠εέδϡʔϥʹΑΓɺ UpstreamͱDownstreamεϨου͕੾ΓସΘΔ receive(on:)Ͱࢦఆͨ͠εέδϡʔϥʹΑΓɺ DownstreamͷεϨου͕੾ΓସΘΔ subscribe(on:)͸Downstream ʹ΋Өڹ͢Δ
  12. /05& 4VCTDSJQUJPOͷಈ࡞͸೚ҙͷͨΊɺ ͜ͷྫͰ͸͜͏͍͏ಈ࡞Λ ͍ͯ͠Δͱ͍͏ྫͰ͔͠ͳ͍Ͱ͢ɻ Publisher͕ .receive(on: scheduler) ͞Ε͍ͯΕ͹ɺSFDFJWF࣌ʹ ࢦఆ͞Εͨ4DIFEVMFS͕ ͦͷΩϡʔͰॲཧΛ࣮ߦ͢Δɻ

    ˣ ͦͷޙͷॲཧ΋ͦͷΩϡʔͰ Ҿ͖ଓ͖࣮ߦ͞ΕΔɻ Publisher͕.subscribe(on: scheduler) ͞Ε͍ͯΕ͹ɺTVCTDSJCF΍SFDFJWF͞Εͨࡍ ࢦఆ͞Εͨ4DIFEVMFSͷϓϩτίϧͷϝιουͰ ॲཧΛ࣮ߦ͢Δ͜ͱͰΩϡʔΛ੾Γସ͑Δɻ ˣ 1VCMJTIFSͷΠϕϯτॲཧٴͼɺͦͷޙͷॲཧ΋ ੾Γସ͑ΒΕͨΩϡʔͰҾ͖ଓ͖࣮ߦ͞ΕΔɻ
  13. ਖ਼֬͞ͷͨΊͷิ଍ -> ཧ۶͕Θ͔ͬͨ͸ͣ • subscribe(on:) • UpstreamͷεϨουΛ੾Γସ͑Δ͕ɺDownstremʹ΋Өڹ͕͋Δ • subscribe͞Εͨࡍ΍request͞Εͨࡍʹಈ࡞͢ΔεέδϡʔϥΛܾΊΔʢ࣮͸΋͏গ͠ ࡉ͔͘Ωϟϯηϧ͞Εͨࡍ΋ͦͷεέδϡʔϥ͕ಈ͘ʣ

    • receive(on:) • DownstreamͷΈεϨουΛ੾Γସ͑Δ • Subscriber͕receiveͨ͠ࡍʹಈ࡞͢ΔεέδϡʔϥΛܾΊΔ https://developer.apple.com/documentation/combine/publishers/handleevents/subscribe(on:options:)
  14. // ݱࡏ͔࣌ؒΒࢦఆ࣌ؒΛਐΊͨ࣌ؒ finalDate // ݱࡏ࣌ؒ <= ਐΊͨ࣌ؒͳΒ ͦͷؒϧʔϓʢͭ·Γݱࡏ࣌ؒ͸ਐΊΒΕΔʣ // scheduledऔΓग़ͤͨΒΞΫγϣϯΛ࣮ߦͯ͠࡟আ͓ͯ͘͠

    // ݱࡏ࣌ؒΛਐΊͨ࣌ؒ͸ɺ·ͩεέδϡʔϧ͞ΕͨΠϕϯτͷ࣌ؒʹಧ͍ͯͳ͍ͷͰ // ݱࡏ࣌ؒΛਐΊͨ࣌ؒ >= εέδϡʔϧ͞ΕͨΠϕϯτ࣌ؒ now nextDate finalDate advance(by:)
  15. // ݱࡏ͔࣌ؒΒࢦఆ࣌ؒΛਐΊͨ࣌ؒ finalDate // ݱࡏ࣌ؒ <= ਐΊͨ࣌ؒͳΒ ͦͷؒϧʔϓʢͭ·Γݱࡏ࣌ؒ͸ਐΊΒΕΔʣ // scheduledऔΓग़ͤͨΒΞΫγϣϯΛ࣮ߦͯ͠࡟আ͓ͯ͘͠

    // ݱࡏ࣌ؒΛਐΊͨ࣌ؒ͸ɺ·ͩεέδϡʔϧ͞ΕͨΠϕϯτͷ࣌ؒʹಧ͍ͯͳ͍ͷͰ // ݱࡏ࣌ؒΛਐΊͨ࣌ؒʹͯ͠ advance(by:)Λऴྃ // ݱࡏ࣌ؒΛਐΊͨ࣌ؒ >= εέδϡʔϧ͞ΕͨΠϕϯτ࣌ؒ now nextDate finalDate advance(by:)
  16. // ݱࡏ͔࣌ؒΒࢦఆ࣌ؒΛਐΊͨ࣌ؒ finalDate // ݱࡏ࣌ؒ <= ਐΊͨ࣌ؒͳΒ ͦͷؒϧʔϓʢͭ·Γݱࡏ࣌ؒ͸ਐΊΒΕΔʣ // scheduledऔΓग़ͤͨΒΞΫγϣϯΛ࣮ߦͯ͠࡟আ͓ͯ͘͠

    // ݱࡏ࣌ؒΛਐΊͨ࣌ؒ͸ɺ·ͩεέδϡʔϧ͞ΕͨΠϕϯτͷ࣌ؒʹಧ͍ͯͳ͍ͷͰ // ݱࡏ࣌ؒΛਐΊͨ࣌ؒʹͯ͠ advance(by:)Λऴྃ // ݱࡏ࣌ؒΛεέδϡʔϧ͞ΕͨΠϕϯτ࣌ؒ·ͰਐΊΔ // ݱࡏ࣌ؒΛਐΊͨ࣌ؒ >= εέδϡʔϧ͞ΕͨΠϕϯτ࣌ؒ now nextDate finalDate advance(by:)