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
快速入門可觀測性
blueswen
0
350
The Efficiency Paradox and How to Save Yourself and the World
hollycummins
1
440
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
Webエンジニア主体のモバイルチームの 生産性を高く保つためにやったこと
igreenwood
0
330
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
Zoneless Testing
rainerhahnekamp
0
120
Beyond ORM
77web
5
660
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
140
HTTP compression in PHP and Symfony apps
dunglas
2
1.7k
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
return文におけるstd::moveについて
onihusube
1
1.1k
Refactor your code - refactor yourself
xosofox
1
260
Featured
See All Featured
Navigating Team Friction
lara
183
15k
Documentation Writing (for coders)
carmenintech
66
4.5k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
How to Ace a Technical Interview
jacobian
276
23k
How STYLIGHT went responsive
nonsquared
95
5.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Practical Orchestrator
shlominoach
186
10k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
98
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
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Λ ͬͨ΄͏͕ରশੑ౷Ұײ͕͋Δͷ͔Δ