Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
RxSwift-MVVM
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
chocovayashi
July 24, 2018
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxSwift-MVVM
chocovayashi
July 24, 2018
More Decks by chocovayashi
See All by chocovayashi
iosの新機能軽く使ってみた
chocovayashi
0
78
Other Decks in Programming
See All in Programming
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
380
Webの地図
yosuke_furukawa
PRO
6
4.8k
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
130
Intent as Code
shoppingjaws
6
1.1k
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
3k
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
120
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
580
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
170
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.2k
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
850
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
4.1k
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
170
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
550
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
920
Navigating Weather and Climate Data
rabernat
0
540
The Invisible Side of Design
smashingmag
301
52k
We Are The Robots
honzajavorek
0
380
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
540
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の 非同期処理を実現できる。 けど、学習コストが高い( ´∀`) 導入するかはチームで要相談