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

iOS Apple Dev Tutorialsとpointfreeのモダン実装を比較する

iOS Apple Dev Tutorialsとpointfreeのモダン実装を比較する

ああうえ

July 20, 2023
Tweet

More Decks by ああうえ

Other Decks in Programming

Transcript

  1. ͋͋͏͑(@_kwzr_)
    iOS Apple Dev Tutorialsͱ


    pointfreeͷϞμϯ࣮૷Λൺֱ͢Δ

    View full-size slide

  2. ࣗݾ঺հ
    • ͋͋͏͑(@_kwzr_)


    • ॴଐ: ৽نࣄۀ෦ɾCTOࣨσβΠϯγεςϜ෦


    • ࢓ࣄ: ଟ෼iOSΤϯδχΞ


    • झຯ: εϓϥɾ͓ֆ͔͖

    View full-size slide

  3. iOS։ൃΛֶͿʹ͸...

    View full-size slide

  4. AppleͷνϡʔτϦΞϧ΍ͬͱ͍ͯʂ

    View full-size slide

  5. AppleͷνϡʔτϦΞϧΛ


    ΍͍ͬͯͩ͘͞

    View full-size slide

  6. iOS Apple Dev Tutorials
    • SwiftUIͱUIKitͷνϡʔτϦΞϧ͕͋Δ


    • εςοϓ͝ͱʹஸೡͳઆ໌


    • ϖʔδͷ࠷ޙʹ͸໰୊͕͋Γɺཧղ౓
    ΛνΣοΫͰ͖Δ
    https://developer.apple.com/tutorials/app-dev-training

    View full-size slide

  7. Scrumdinger(Standups)
    • SwiftUI൛Ͱ࣮૷͞Ε͍ͯΔΞϓϦ


    • λΠϚʔΛઃఆͰ͖ͨΓɺձٞͷ಺༰Λ࿥Ի
    ͨ͠ΓɺࢀՃऀΛه࿥Ͱ͖ΔΞϓϦ

    View full-size slide

  8. νϡʔτϦΞϧͰֶͿ͜ͱ
    • ϨΠΞ΢τ(VStack, HStack...)


    • ΞΫηγϏϦςΟରԠํ๏


    • ϞσϧΛ࡞ͬͯListʹ൓ө


    • ը໘ભҠ(NavigationStack)


    • ঢ়ଶ؅ཧ(@State, @Binding, ObservableObject, ...)


    • ϥΠϑαΠΫϧ(onAppear, onDisappear)

    View full-size slide

  9. νϡʔτϦΞϧͰֶͿ͜ͱ
    • Swift Concurrency


    • File ManagerΛ࢖ͬͨӬଓԽ


    • গ͠ൃలతͳඳը(PathͳͲ)


    • Τϥʔը໘ͷදࣔ


    • OSͷAPIݺͼग़͠(Speech framework΍ݖݶͷڐՄ)


    • ͳͲ

    View full-size slide

  10. (΋͏͜Ε࢓ࣄ͡ΌΜ)

    View full-size slide

  11. iOSΞϓϦ։ൃΛֶͼ͍ͨਓʹ


    ͱͯ΋͓͢͢Ίʂʂ

    View full-size slide

  12. νϡʔτϦΞϧ͸΍ͬͨɺ͜ͷઌͲ͏͢Ε͹...
    • UIKitͱֶ͔ͼ͍ͨ → UIKitνϡʔτϦΞϧɺpixivͷνϡʔτϦΞϧ


    • ΞʔΩςΫνϟͱ͔ςετͱ͔


    • യવͱɺΑΓྑ͍ίʔυΛॻ͖͍ͨͱ͔

    View full-size slide

  13. pointfreeͷϞμϯ࣮૷ͱൺ΂Δ

    View full-size slide

  14. pointfreeco/standups
    • TCAΛ࡞͍ͬͯΔpointfree͕࡞͍ͬͯΔ


    • ScrumdingerΛΑΓϞμϯʹॻ͍ͯΈͨϓϩδΣΫτ

    View full-size slide

  15. Ϟμϯ #ͱ͸

    View full-size slide

  16. ϓϩδΣΫτߏ੒Λൺֱ͢Δ

    View full-size slide

  17. φϏήʔγϣϯपΓͷൺֱ

    View full-size slide

  18. ϓϩδΣΫτߏ੒ΛݟΔ
    • 2ͭͷϓϩδΣΫτ͕͋ͬͨ


    • StackBased


    • TreeBased

    View full-size slide

  19. StackBased vs TreeBased
    • StackBased


    • AppViewͰNavigationStack(path:)ΛݟͯɺϧʔςΟϯά


    • TreeBased


    • ֤View͔ΒnavigationDestinationΛ࢖֤ͬͯը໘ʹભҠ͍ͯ͠Δ


    • ͦΕͧΕϝϦσϝ͋Γɺ͜Ε͕׬શਖ਼ղͱ͍͏΋ͷ͸ݱঢ়ͳ͍

    View full-size slide

  20. ঢ়ଶϕʔεͷφϏήʔγϣϯʹ͍ͯ͠Δ
    • pointfreeco/swiftui-navigation


    • SwiftUIͷը໘ભҠͷ໰୊Λղܾ͍ͯ͠ΔϥΠϒϥϦ


    • NavigationLink΍TabView͸ঢ়ଶͱը໘ભҠ͕ඥ͔ͮͳ͍


    • ྻڍܕΛ࢖ͬͯը໘ભҠͰ͖ΔΑ͏ʹ͍ͯ͠Δ


    • DeepLinkͳͲΛ͠΍͘͢ͳΔ

    View full-size slide

  21. ςετͷൺֱ

    View full-size slide

  22. ςετίʔυ͕ॻ͔Ε͍ͯΔ
    • AppleͷνϡʔτϦΞϧʹςετ͸ॻ͔Ε͍ͯͳ͍͕ɺpointfreeͷํ͸
    ςετ͕ॻ͔Ε͍ͯΔ


    • ViewModelతͳ΍ͭͷϢχοτςετ


    • ςετΛॻ͚ΔΑ͏ʹ͍ͯ͠Δ(େࣄ)

    View full-size slide

  23. ViewͷϩδοΫɾঢ়ଶʹؔ͢Δςετ͕ॻ͚Δ
    • جຊతʹViewͷϢχοτςετΛॻ͘ͷ͸೉͍͠


    • ϥΠϒϥϦΛ࢖͏ͳͲ͢Ε͹Ͱ͖Δ͕...


    • https://github.com/nalexn/ViewInspector


    • Ұൠతͳํ਑: ViewModelతͳ΋ͷΛ࡞ΓɺϩδοΫͱঢ়ଶʹؔ͢Δς
    ετΛॻ͘

    View full-size slide

  24. Apple νϡʔτϦΞϧͰςετΛॻ͍ͯΈΔ
    • MeetingViewͰ࢖ΘΕ͍ͯΔScrumTimerΫϥε͸λΠϚʔ + ݱࡏͷൃ
    දऀͷঢ়ଶΛ࣋ͭModel


    • ޾͍ɺViewʹঢ়ଶ͕΂ͬͨΓॻ͔Ε͍ͯΔײ͡Ͱ͸ͳ͔ͬͨͷͰɺλΠ
    Ϛʔ+ঢ়ଶͷςετΛॻ͚ͨ

    View full-size slide

  25. pointfreeͷtimerͷςετ
    • Dateͷ୅ΘΓʹclockΛ࢖͍ɺςετίʔυͰ࣌ؒΛਐΊΒΕΔΑ͏ʹ
    ͍ͯ͠Δ

    View full-size slide

  26. Dependency InjectionΛ͍ͯ͠Δ
    • pointfreeco/swift-dependencies

    View full-size slide

  27. swift-dependencies͕ͳ͍ͱ͖
    • ී௨ʹ΍Δͱςετ༻ͷϞοΫΛࠩ͠ࠐΜͩΓ͢ΔͨΊʹɺί
    ϯετϥΫλͳͲͰΠϯελϯεΛ౉ͨ͠Γ͢Δඞཁ


    • ໘౗ɻόέπϦϨʔ͠ͳ͖Ό͍͚ͳ͍࣌͸΋ͬͱ໘౗

    View full-size slide

  28. ஋ͷఏڙ
    • SpeechClientͷΠϯελϯεΛఏڙ
    ͍ͨ͠৔߹͸ӈͷΑ͏ʹॻ͘


    • ςετ༻ɺϓϨϏϡʔ༻ͷ஋Λఏڙ
    Մೳ

    View full-size slide

  29. • @Dependency(\.speechClient)ͰSpeechClientͷΠϯελϯεΛऔͬͯ
    དྷͯ͘ΕΔΑ͏ʹ


    • Property WrapperͰ࢖͑ͯศར


    • Clock΍UUIDͳͲɺΑ͘࢖͏΋ͷΛඪ४Ͱఏڙ
    swift-dependencies͕͋Δͱ͖

    View full-size slide

  30. SpeechRecognizer
    • ݩʑͷSpeechRecognizer


    • Ի੠ೝࣝ݁ՌΛड͚औΔ + ݁ՌΛอ࣋͢Δ
    AppleͷνϡʔτϦΞϧ

    View full-size slide

  31. pointfree൛ SpeechClient
    • AsyncThrowingStreamͰྲྀ͚ͩ͢ʹ͍ͯ͠Δ

    View full-size slide

  32. ࡉ͔͍ॻ͖ํͳͲ
    • ViewଆͰ࢖͏༻ʹInt, Doubleͷ
    ϓϩύςΟΛ࡞͍ͬͯΔ


    • গࠞ͠ཚͦ͠͏
    AppleͷνϡʔτϦΞϧ

    View full-size slide

  33. Durationܕͷ࢖༻
    • Durationܕ(iOS 16+)ʹஔ͖׵Θ͓ͬͯΓɺformatͳͲ͸ViewଆͰߦͬͯ
    ͍Δ
    pointfreeͷ࣮૷

    View full-size slide

  34. • iOS 16͔Β࢖͑Δγϯϓϧͳ΋ͷʹ
    DocumentDirectoryͷऔಘํ๏

    View full-size slide

  35. Previewͷઆ໌จ
    • ϓϨϏϡʔͷઆ໌จΛදࣔ͢ΔViewΛࠩ͠ࠐΜͰ͍Δ

    View full-size slide

  36. ࿔ΒΕ͍ͯͳ͔ͬͨ৔ॴ
    • SwiftUIͷView͸ಛʹมߋͯ͠ͳͦ͞͏


    • ݩ͔Β͔ͳΓ៉ྷʹ࡞ΒΕ͍ͯΔͱࢥͬͨ

    View full-size slide

  37. ͕࣌ؒͳͯ͘࿩ͤͳ͔ͬͨͱ͜Ζ
    • Identi
    fi
    edArrayͷ࿩


    • pointfreeతʹ͸ਪ͠ϙΠϯτͬΆ͍


    • ύϑΥʔϚϯε͕ߴ͍ListΛॻ͖΍͘͢


    • Ϟνϕʔγϣϯͷจ຺Λ࿩͚ͩ͢Ͱֻ͕͔࣌ؒͬͯ͠·͏


    • Sendableॻ͍ͯͨΓ

    View full-size slide

  38. Ϟμϯͱ͸
    • ΑΓྑ͍φϏήʔγϣϯ


    • DeepLink͠΍͘͢


    • ςελϏϦςΟ


    • DI


    • ੹຿ͷ෼ׂ


    • ύϑΥʔϚϯε


    • Identi
    fi
    edArray


    • ΑΓ୹͘ॻ͚ΔAPI

    View full-size slide

  39. Apple࣮૷ͷ؆ܿ͞΋ྑ͍
    • ΞϓϦ։ൃ࢝Ίͨͯͷਓ͕ύϑΥʔϚϯε΍ςελϏϦςΟΛؾʹ͢͠
    ͗ͯԿ΋࣮૷Ͱ͖ͳ͘ͳΔͷ΋Α͘ͳ͍

    View full-size slide

  40. ͳΜͱTCA൛࣮૷΋͋Δ

    View full-size slide

  41. TCAͷExamplesʹStandups͕௥Ճ͞Εͨ
    • pointfreeco/swift-composable-architecture


    • 5݄ʹϦϦʔε͞ΕͨTCAͷNavigationػೳͱڞʹStandupsͷαϯϓϧ
    ΋௥Ճ͞Εͨ

    View full-size slide

  42. pointfreeco/standupsͷඍົ͞Λײ͡Δ఺
    TreeBasedͷίʔυ͕ͩɺStackBasedͰ΋ࣅͨΑ͏ͳ͜ͱΛ΍͍ͬͯΔ

    View full-size slide

  43. pointfreeco/standupsͷඍົ͞Λײ͡Δ఺
    TreeBasedͷίʔυ͕ͩɺStackBasedͰ΋ࣅͨΑ͏ͳ͜ͱΛ΍͍ͬͯΔ
    ↓ͳΜ͔ॻ͖๨Εͦ͏

    View full-size slide

  44. • ࢠ(ભҠઌ)ͷΞΫγϣϯ΋Reducer಺ͷenumͰ໢ཏతʹॻ͚Δ
    TCA

    View full-size slide

  45. TCA͍͍ͧ


    (झࢫ͕ͣΕ͖ͯͦ͏)
    ͜Ε͚ͩͰ͸ͳ͍͚Ͳ...

    View full-size slide

  46. ·ͱΊ
    • AppleͷνϡʔτϦΞϧ࣮૷ͱpointfreeͷϞμϯ࣮૷Λൺֱͨ͠


    • ςελϏϦςΟ΍ύϑΥʔϚϯεΛҙࣝ͢Δ͜ͱͰϞμϯͳ࣮૷ʹɻ࣮
    ૷͸ެ։͞Ε͍ͯΔͷͰൺֱͯ͠ΈΑ͏ʂ

    View full-size slide

  47. AppleͷνϡʔτϦΞϧ΍ͬͱ͍ͯʂ
    ↑ͪͳΈʹ͜ͷਓ͸ΤΞϓɻνϡʔτϦΞϧ΍ͬͨ͜ͱ͋Γ·ͤΜ

    View full-size slide

  48. ࢀߟ
    • https://www.pointfree.co/blog/posts/99-modern-swiftui


    • pointfreeͷ༗ྉهࣄ͸ཧղͷ֬ೝͷΈʹ࢖ͬͯ·͢

    View full-size slide