Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
TCAでViewStoreにKeyPath DynamicMemberLookupが使われてる件
Search
yimajo
November 22, 2020
Programming
0
1k
TCAでViewStoreにKeyPath DynamicMemberLookupが使われてる件
iOSアプリ開発のためのFunctional Architecture情報共有会2 の発表資料です。
https://connpass.com/event/194239/
yimajo
November 22, 2020
Tweet
Share
More Decks by yimajo
See All by yimajo
良いテストコードのために悪いテストコードを理解する - 不安定なテスト編: iOSアプリ開発ユニットテストの場合
yimajo
22
5.7k
TCAの Shared Stateって どういう仕組みになってんの?
yimajo
0
1.4k
Swift 5.9 からの Observation はiOS17 未満 からも使えて struct の変更検知もできるんすかね?
yimajo
2
670
不安定なテストは200種類あんねん
yimajo
3
800
TCA v0.19.0からのSwitchStore/CaseLetが良い
yimajo
0
1.8k
TCAでのClient/Managerの 利用パターンでは副作用のActionやErrorを分離できる
yimajo
0
790
【開催説明資料】iOSアプリ開発のための Functional Architecture 情報共有会
yimajo
0
230
SWORD ART COMBINE
yimajo
1
1.1k
iOSアプリ開発のためのThe Composable Architectureがすごく良いので紹介したい
yimajo
5
4.1k
Other Decks in Programming
See All in Programming
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
940
Jakarta EE meets AI
ivargrimstad
0
650
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
230
Ethereum_.pdf
nekomatu
0
460
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
Featured
See All Featured
Navigating Team Friction
lara
183
14k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Agile that works and the tools we love
rasmusluckow
327
21k
Designing Experiences People Love
moore
138
23k
Why Our Code Smells
bkeepers
PRO
334
57k
Writing Fast Ruby
sferik
627
61k
Teambox: Starting and Learning
jrom
133
8.8k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Thoughts on Productivity
jonyablonski
67
4.3k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Transcript
TCAͰViewStoreͷStateʹ KeyPath DynamicMemberLookup͕ɹ ΘΕͯΔ݅ @yimajo 2020/11/22 #fa_ios iOSΞϓϦ։ൃͷͨΊͷFunctional Architectureใڞ༗ձ2
TCAKeyPathʹΑΔ DynamicMemberLookupͬͯΜͷ͓͢ Εʔʂ ͜Ε͍͍ײ͡ͷ͍ํʔ
ຊʹͦ͏͔ʁ ඞવੑͷ͋Δ͍ํ͔ʁ
͍͍͍ɺ͍͍Ͱ͠ΐɻ Swift 4͘Β͍͔Βͷ KeyPath ɺ ͦͯ͠ Swift 4.2 ͔Βͷ Dynamic
Member Lookupɺ ͜ΕΛ্ख͍͜ͱΈ߹Θͤͨ Swift 5.1 ͔Βͷ Key Path ʹΑΔ Dynamic Member Lookup Μɺ ͜ΕΛͬͯΔͱؒతʹͰStateʹܕͰΞΫηε Ͱ͖ͯؾ࣋ͪ͑ʔΜɺͦΕҎ্ͷԿ͕͋Μͷʔʁ
͜ΕͩΊͩɺௐͯ ߟ͑ͯ͠ΈΑ͏͔…
ࠓճͷͷ֓ཁ
ࠓճͷͷ֓ཁ • TCAͰKeyPathʹΑΔDynamic Member LookupʢҎ߱ KeyPath Member Lookupʣ ͕ΘΕ͍ͯΔ
ࠓճͷͷ֓ཁ • TCAͰKeyPathʹΑΔDynamic Member LookupʢҎ߱ KeyPath Member Lookupʣ ͕ΘΕ͍ͯΔ •
SwiftUI.View ͔Β State ͷΛݟΔͱ͖ͳͲ
ࠓճͷͷ֓ཁ • TCAͰKeyPathʹΑΔDynamic Member LookupʢҎ߱ KeyPath Member Lookupʣ ͕ΘΕ͍ͯΔ •
SwiftUI.View ͔Β State ͷΛݟΔͱ͖ͳͲ • ҙຯ͋Δͷʁॴ͋Δͷʁඞવੑʁ
ࠓճͷͷ֓ཁ • TCAͰKeyPathʹΑΔDynamic Member LookupʢҎ߱ KeyPath Member Lookupʣ ͕ΘΕ͍ͯΔ •
SwiftUI.View ͔Β State ͷΛݟΔͱ͖ͳͲ • ҙຯ͋Δͷʁॴ͋Δͷʁඞવੑʁ • ͜Ε SwiftUI.View ͚ͩݟͯΔͱҙຯඞવੑ͔ΓͮΒ͍͔
ࠓճͷͷ֓ཁ • TCAͰKeyPathʹΑΔDynamic Member LookupʢҎ߱ KeyPath Member Lookupʣ ͕ΘΕ͍ͯΔ •
SwiftUI.View ͔Β State ͷΛݟΔͱ͖ͳͲ • ҙຯ͋Δͷʁॴ͋Δͷʁඞવੑʁ • ͜Ε SwiftUI.View ͚ͩݟͯΔͱҙຯඞવੑ͔ΓͮΒ͍͔ • TCAͰͳ͍ઃܭҰԠৼΓฦΔ
ࠓճͷͷ֓ཁ • TCAͰKeyPathʹΑΔDynamic Member LookupʢҎ߱ KeyPath Member Lookupʣ ͕ΘΕ͍ͯΔ •
SwiftUI.View ͔Β State ͷΛݟΔͱ͖ͳͲ • ҙຯ͋Δͷʁॴ͋Δͷʁඞવੑʁ • ͜Ε SwiftUI.View ͚ͩݟͯΔͱҙຯඞવੑ͔ΓͮΒ͍͔ • TCAͰͳ͍ઃܭҰԠৼΓฦΔ • UIKit ͔Β͏߹ΛͬͯΔͱඞવੑ͕͋ΔΑ͏ʹࢥ͑Δ
۩ମྫ
TCA ͷ SwiftUI Χϯλʔαϯϓϧ
TCA ͷ SwiftUI Χϯλʔαϯϓϧ
TCA ͷ SwiftUI Χϯλʔαϯϓϧ • SwiftUI͕storeΛอ࣋
TCA ͷ SwiftUI Χϯλʔαϯϓϧ • SwiftUI͕storeΛอ࣋ • store͔ΒviewStoreมऔΓग़͠
TCA ͷ SwiftUI Χϯλʔαϯϓϧ • SwiftUI͕storeΛอ࣋ • store͔ΒviewStoreมऔΓग़͠ • viewStoreܦ༝ͰcountʹΞΫηε
4XJGU6*7JFX 4UPSF4UBUF "DUJPO 4UBUF ViewStore
bow-swift/bow-arch ൺֱͱͯ͠
bow-swift/bow-arch ൺֱͱͯ͠
bow-swift/bow-arch • SwiftUI.View͕stateͱhandleΛอ࣋ ൺֱͱͯ͠
bow-swift/bow-arch • SwiftUI.View͕stateͱhandleΛอ࣋ • handle͕Stateͷૢ࡞ ൺֱͱͯ͠
bow-swift/bow-arch • SwiftUI.View͕stateͱhandleΛอ࣋ • handle͕Stateͷૢ࡞ • ͍ΘΏΔReducer ൺֱͱͯ͠
4XJGU6*7JFX 4UBUF )BOEMF
࣮ࡍ TCA Ͱ KeyPath Member Lookup ͨ͘͠ͳΔؾ͔࣋ͪΔ͕ ͳͯ͘ྑ͍ؾ͢Δ
UIKitͰͷTCAͷ͍ํΛݟͯΈΔ
TCAͰUIKitͰͷ Χϯλʔαϯϓϧ … লུ
TCAͰUIKitͰͷ Χϯλʔαϯϓϧ … লུ
TCAͰUIKitͰͷ Χϯλʔαϯϓϧ • viewStore.publisher Ͱ $0.count … লུ
TCAͰUIKitͰͷ Χϯλʔαϯϓϧ • viewStore.publisher Ͱ $0.count • ͦͷΛUITextLabelͷtextʹ … লུ
TCAͰUIKitͰͷ Χϯλʔαϯϓϧ • viewStore.publisher Ͱ $0.count • ͦͷΛUITextLabelͷtextʹ … লུ
ͭ·Γ State ͕ Publisher ͰऔಘͰ͖Δ
ViewStoreΈͯΈΔ
ViewStoreΈͯΈΔ • publisher: StorePublisher<State>
ViewStoreΈͯΈΔ • publisher: StorePublisher<State> StorePublisher Λ ͞Βʹৄ͘͠Γ͍ͨ
StorePublisherΈͯΈΔ
StorePublisherΈͯΈΔ • StorePublisherPublisherʹ४ڌͯ͠ ͍ΔͷͰStateΛετϦʔϜʹྲྀͤΔ
StorePublisherΈͯΈΔ • StorePublisherPublisherʹ४ڌͯ͠ ͍ΔͷͰStateΛετϦʔϜʹྲྀͤΔ
StorePublisherΈͯΈΔ • StorePublisherPublisherʹ४ڌͯ͠ ͍ΔͷͰStateΛετϦʔϜʹྲྀͤΔ • ͞Βʹ subscript Ͱmapͯ͠Δ
StorePublisherΈͯΈΔ • StorePublisherPublisherʹ४ڌͯ͠ ͍ΔͷͰStateΛετϦʔϜʹྲྀͤΔ • ͞Βʹ subscript Ͱmapͯ͠Δ ͭ·ΓɺStorePublisherʹରͯ͠ KeyPath
Member Lookup ͯ͠ map ͠ Publisher Λฦͯ͠Δ
→ self.viewStore.publisher.count .assign(to: \.text, on: countLabel) .store(in: &self.cancellables) ͭ·Γ …
→ self.viewStore.publisher.count .assign(to: \.text, on: countLabel) .store(in: &self.cancellables) ࠨͷΑ͏ʹࣗલͰ .publisher
ʹ .map Λॻ͔ͳ͍͍ͯ͘ʂ ͭ·Γ …
→ self.viewStore.publisher.count .assign(to: \.text, on: countLabel) .store(in: &self.cancellables) ࠨͷΑ͏ʹࣗલͰ .publisher
ʹ .map Λॻ͔ͳ͍͍ͯ͘ʂ KeyPath Member Lookup ͬͯলུͰ͖Δʢӈʣɻ ͭ·Γ …
None
\\\ ετϦʔϜΛѻ͏ͱ͖ State ͱ͍͏มݟ͑ͳͯ͘ྑͦ͞͏ ///
↓ \\\ ετϦʔϜΛѻ͏ͱ͖ State ͱ͍͏มݟ͑ͳͯ͘ྑͦ͞͏ ///
↓ ετϦʔϜΛѻΘͣ State ͷϓϩύςΟ͕ཉ͍͠ͱ͖ɺ \\\ ετϦʔϜΛѻ͏ͱ͖ State ͱ͍͏มݟ͑ͳͯ͘ྑͦ͞͏ ///
↓ ετϦʔϜΛѻΘͣ State ͷϓϩύςΟ͕ཉ͍͠ͱ͖ɺ State ͱ͍͏มݟ͑ͳ͍΄͏͕ରশੑ͕͋Δ…͔… \\\ ετϦʔϜΛѻ͏ͱ͖ State ͱ͍͏มݟ͑ͳͯ͘ྑͦ͞͏
///
7JFX4UPSF 4UBUF viewStore.count ͍ͩ͘͞ state.count: Int ฦ͢ viewStore.publisher.count ͍ͩ͘͞ StorePublisher<State>͔Β
StorePublisher<Int>ͳ count ฦ͢ ϓϩύςΟͷ ͕ཉ͍͠ 1VCMJTIFSΛ TJOLͯ͠ Ͳ͏ʹ͔͍ͨ͠
͓ΘΓʹ: ٞͷϙΠϯτ • KeyPath Member Lookup ͳͯ͘ྑ͍ͱࢥ͏͚Ͳ • Publisherͱͯ͠ཉ͍͠߹ͷΠϯλϑΣʔεͰ͞Λল͚ͯΔ •
StateͷϓϩύςΟ͕΄͍͠ͱ͖ɺKeyPath Member LookupΛ ͬͨ΄͏͕ରশੑ౷Ұײ͕͋Δͷ͔Δ