スケーラブル SwiftUI プロジェクトのための
実⽤的な TCA 適用及びモジュール化
Principles of building robust module
KyuYoung Heo
@bbvch13531
iOS Developer
目次
• デモ
• Declarative UI and SwiftUI
• The Composable Architecture
• モジュラー化の目的
• ステップ 1: SwiftUI to TCA
• ステップ 2: TCA モジュール化
• ステップ 3: Refactoring
• 結論
デモを実行しましょう
Declarative UI and SwiftUI
struct CounterView: View {
@State var count = 0
var body: some View {
HStack {
Button("-") { count -= 1 }
Text("(count)")
Button("+") { count += 1 }
}
}
}
Data Flow in SwiftUI
Declarative UI
UI = f( state )
The layout
on screen
Builder
methods
The application state
docs.
fl
utter.dev
Data Flow in SwiftUI
Data
fl
ow
Action View
State
👨💻
User Interaction Render
Update
Mutate
WWDC19: Data
fl
ow through SwiftUI
The Composable Architecture
TCA
• TCA は pointfree によって導入されます
• Unidirectional data
fl
ow architecture
• ex) elm, Redux, MVI, ReactorKit
Introduction
TCA
Architecture Diagram
Reducer
State
Action
View
Update
Mutate
Send Handle
Store
TCA
Architecture Diagram
"タップ"
Reducer
State
Action
View
Update
Send Handle
Store
Increment
Mutate
TCA
Architecture Diagram
Reducer
State
Action
View
Update
Mutate
Send Handle
Store
Increment
count=0
TCA
Architecture Diagram
Reducer
State
Action
View
Update
Send Handle
Store
count+=1
Mutate
TCA
Architecture Diagram
Reducer
State
Action
View
Update
Send Handle
Store
count+=1
Mutate
1
TCA
State Management
Reducer
State
Action
View
Update
Mutate
Send Handle
Store
TCA
State Management
Reducer
State
Action
View
Update
Mutate
Send Handle
Store
E
ff
ect Dependency
TCA
• Better State Management
• Easy to debug
• Enhance Testability
• Modularization(Composability)
Bene
fi
ts
Purpose of Modularization
Modularization
• The size of project grows,
the complexity increases exponentially
• Control this complexity is key of
Software Engineering
Purpose
Feature
Complexity
Time
Cost
• High Cohesion, Low Coupling
• Open to Extend, Close to modify
• Dependency Inversion
• Testability
Modularization
SOLID Principle
Modularization
• Composing Modules by Separating of Concerns
• Do Use Access Control(public, internal, private)
• Do access by protocol not by Implementation
• Use Dependencies by DI
• Write Unit Test
Principles for Robust Module
Modularization
• (Reducer + View) could be one component in TCA
• Composing Reducers to build a App
TCA
ステップ 1: SwiftUI to TCA
github.com/bbvch13531/githubsearch
Workshop1
• Change ViewModel to Reducer
• De
fi
ne State, Action
• Handling Action
• Implement GithubAPIClient
SwiftUI to TCA
ステップ 2: TCA モジュラー化
Workshop2
• Add Local Swift Package
• Create Modules according to Directories
• Add Access Control (public, internal, private)
• Inversion of Dependency
TCA Modularization
Workshop2
TCA Modularization
Core
RepoSearch
RepoDetail
Starring
Stargazer
App
Module Structure
ステップ 3: Refactoring
Workshop3
• Inject Dependency using DI Container
• Writing Unit Test
Refactoring
結 論
けつ ろん
Conclusion
• Migrate SwiftUI to TCA
• Seperate project into Modules
• Inject Dependency
• Writing Unit Test
What we've done
Conclusion
• How to compose module with high cohesion and low coupling
What we've learn
ありがとうございます。
KyuYoung Heo
@bbvch13531
iOS Developer

スケーラブル SwiftUI プロジェクトにおける実用的な TCA モジュラー化