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.5k
Swift 5.9 からの Observation はiOS17 未満 からも使えて struct の変更検知もできるんすかね?
yimajo
2
700
不安定なテストは200種類あんねん
yimajo
3
830
TCA v0.19.0からのSwitchStore/CaseLetが良い
yimajo
0
1.8k
TCAでのClient/Managerの 利用パターンでは副作用のActionやErrorを分離できる
yimajo
0
810
【開催説明資料】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
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
Zoneless Testing
rainerhahnekamp
0
120
CSC509 Lecture 14
javiergs
PRO
0
140
Beyond ORM
77web
3
380
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
talk-with-local-llm-with-web-streams-api
kbaba1001
0
180
快速入門可觀測性
blueswen
0
340
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
700
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
Criando Commits Incríveis no Git
marcelgsantos
2
170
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Embracing the Ebb and Flow
colly
84
4.5k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
How to Ace a Technical Interview
jacobian
276
23k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Facilitating Awesome Meetings
lara
50
6.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Designing for humans not robots
tammielis
250
25k
The Cult of Friendly URLs
andyhume
78
6.1k
Statistics for Hackers
jakevdp
796
220k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
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Λ ͬͨ΄͏͕ରশੑ౷Ұײ͕͋Δͷ͔Δ