Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
680
不安定なテストは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
@nifty天気予報のフロントエンドを 実装するまで - NIFTY Tech Talk #22
niftycorp
PRO
0
120
Modular Monolith Monorepo ~シンプルさを保ちながらmonorepoのメリットを最大化する~
yuisakamoto
10
3.4k
Thoughts and experiences on Rust and TypeScript
unvalley
2
180
Vapor Revolution
kazupon
2
2.2k
subpath importsで始めるモック生活
10tera
0
380
事業成長を爆速で進めてきたプロダクトエンジニアたちの成功談・失敗談
nealle
2
450
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
400
新規学習のハードルを下げる方法とは?/ How to Make Learning Something New Easier?
nobuoooo
1
120
Full stack testing :: basic to basic
up1
1
650
Remix on Hono on Cloudflare Workers
yusukebe
1
360
Leveling Up Developer Tooling for the Modern Rails & Hotwire Era @ Ruby Türkiye, November 2024
marcoroth
0
150
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
110
Featured
See All Featured
Optimizing for Happiness
mojombo
376
70k
Speed Design
sergeychernyshev
25
630
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Automating Front-end Workflow
addyosmani
1366
200k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Testing 201, or: Great Expectations
jmmastey
39
7.1k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Designing for humans not robots
tammielis
250
25k
Practical Orchestrator
shlominoach
186
10k
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Λ ͬͨ΄͏͕ରশੑ౷Ұײ͕͋Δͷ͔Δ