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
受け取る人から提供する人になるということ
little_rubyist
0
230
CSC509 Lecture 09
javiergs
PRO
0
140
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
RubyLSPのマルチバイト文字対応
notfounds
0
120
C++でシェーダを書く
fadis
6
4.1k
CSC509 Lecture 11
javiergs
PRO
0
180
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Adopting Sorbet at Scale
ufuk
73
9.1k
Rails Girls Zürich Keynote
gr2m
94
13k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Practical Orchestrator
shlominoach
186
10k
We Have a Design System, Now What?
morganepeng
50
7.2k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Making Projects Easy
brettharned
115
5.9k
Navigating Team Friction
lara
183
14k
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Λ ͬͨ΄͏͕ରশੑ౷Ұײ͕͋Δͷ͔Δ