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
RxSwift-MVVM
Search
chocovayashi
July 24, 2018
Programming
0
130
RxSwift-MVVM
chocovayashi
July 24, 2018
Tweet
Share
More Decks by chocovayashi
See All by chocovayashi
iosの新機能軽く使ってみた
chocovayashi
0
71
Other Decks in Programming
See All in Programming
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.3k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
410
Cell-Based Architecture
larchanjo
0
150
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
470
The Art of Re-Architecture - Droidcon India 2025
siddroid
0
140
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
840
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
220
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
4k
Context is King? 〜Verifiability時代とコンテキスト設計 / Beyond "Context is King"
rkaga
10
1.4k
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
310
Implementation Patterns
denyspoltorak
0
130
LLM Çağında Backend Olmak: 10 Milyon Prompt'u Milisaniyede Sorgulamak
selcukusta
0
140
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
39k
sira's awesome portfolio website redesign presentation
elsirapls
0
91
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
0
320
Testing 201, or: Great Expectations
jmmastey
46
7.8k
Visualization
eitanlees
150
16k
Test your architecture with Archunit
thirion
1
2.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
98
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
31
Code Reviewing Like a Champion
maltzj
527
40k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
260
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
Transcript
RxSwiftを使った iOSアプリ開発の設計 @chocovayashi
今日のゴール RxSwiftを使ってMVVMの 実装ができるようになる
目次 • RxSwiftの説明 ◦ What is RxSwift ◦ When use
RxSwift ◦ How to use RxSwift ◦ RxSwift導入よる利点 • 実際に実装してみよう ◦ Rx入れないMVVM ◦ Rx入れるMVVM • まとめ
目次 • RxSwiftの説明 ◦ What is RxSwift ◦ When use
RxSwift ◦ How to use RxSwift ◦ RxSwift導入よる利点 • 実際に実装してみよう ◦ Rx入れないMVVM ◦ Rx入れるMVVM • まとめ
What is RxSwift RxSwift = Rx + Swift Rx =
Reactive Extensions Reactive Extensionsとは・・ イベントストリームを抽象化するライブラリ
時間 【特徴】 • 値、エラー、完了の3種類のイベントが流れる。 • エラー、完了が流れると、それ以降イベントは流れない。 • イベントをlistenすることをsubscribeすると言う。 イベントが流れてくる川のようなイメージ What
is RxSwift ストリーム
When use RxSwift UIイベント 通信処理 ボタンのタップや、TextFieldの入力、 TableViewへのデータのbindなど HTTP Requestを送信する場合など
How to use RxSwift (UIButton) tapイベント
入力イベント How to use RxSwift (UITextField)
2 5 8 変更イベント How to use RxSwift (KVO)
RxSwift導入による利点 非同期処理が簡単に実現可能
可読性の向上 RxSwift使わない場合 RxSwift使わない場合 メソッドの目移りが なくなる RxSwift導入による利点
イベントの加工や結合などが簡単にできる 1 2 3 2 4 6 map { $0
* 2 } 1 2 3 6 reduce(0) { $0 + $1 } RxSwift導入による利点
1 2 3 ストリームの結合などが簡単にできる 1 2 3 4 5 6
(例) merge observable1 observable2 4 5 6 output RxSwift導入による利点
1 2 3 ストリームの結合などが簡単にできる 1 2 3 4 5 6
(例) concat observable1 observable2 4 5 6 output RxSwift導入による利点
目次 • RxSwiftの説明 ◦ What is RxSwift ◦ When use
RxSwift ◦ How to use RxSwift ◦ RxSwift導入よる利点 • 実際に実装してみよう ◦ Rx入れないMVVM ◦ Rx入れるMVVM • まとめ
今回つくるもの Github APIにアクセスして その内容をViewに表示するア プリ
MVVM作成(共通) Entityの定義 swift4から導入された、 codableを用いて、CodingKeysに jsonのkeyを書くことにより 自動で構造体にマッピング される。
MVVM作成(共通) Requestの定義
Rxを入れないMVVM ライブラリを使わないMVVM • willSet / didSetを用いるパターン • Notificationを使うパターン 動的に監視を追加、削除が可能なので 今回はNotificationを利用
Rxを入れないMVVM Notification.Nameの拡張 keyを通知送信側と受信側で直接書くのは危ういので、 Extentionを用いて Notification.Name の拡張をすべき
Modelの実装 notificationの送信 Rxを入れないMVVM
ViewModelの実装 notificationの受け取り準備 notificationの解放 Rxを入れないMVVM
KVOのデメリット • 毎回解放するのが面倒 • Notification.Nameの拡張が大量に必要となる • 可読性が低い Rxを入れないMVVM
RxSwiftとAPIKitを連携するために、Sessionを拡張 Rxを入れるMVVM
Model Rxを入れるMVVM
ViewModel 取得したEntityを変数にbind VCからsubscribeされるもの Rxを入れるMVVM
ViewController VMでbindされたentityをlistenする VMを通じてデータを取得する Rxを入れるMVVM
RxSwiftのメリット • データの流れをシンプルに書ける • 可読性が高い RxSwiftのデメリット • 学習コストが高い Rxを入れるMVVM
まとめ RxSwiftを使うとシンプルにMVVMの 非同期処理を実現できる。 けど、学習コストが高い( ´∀`) 導入するかはチームで要相談