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でTwitterの ライブラリを作ってる話 / RxTwift
Search
Mihyaeru
March 12, 2016
Technology
800
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxSwiftでTwitterの ライブラリを作ってる話 / RxTwift
RxSwiftでTwitterの ライブラリを作ってる話
Mihyaeru
March 12, 2016
More Decks by Mihyaeru
See All by Mihyaeru
会計 freee バックエンドの今後 / freee backend api
mihyaeru21
8
27k
Railsで実装されている機能のマイクロサービスへの切り離し / split to microservices from rails
mihyaeru21
1
880
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
330
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
740
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.7k
入門ReactiveX / about ReactiveX
mihyaeru21
3
520
RxSwiftと愉快な仲間たち / RxSwift with Units
mihyaeru21
4
2.9k
CrystalでTwitter botを作ってみた / Create a Twitter bot in Crystal
mihyaeru21
0
1.4k
Gotanda.pm #1
mihyaeru21
1
200
Other Decks in Technology
See All in Technology
AI駆動開発の時代になったのでトヨタ生産方式から見直す
terurou
7
6k
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
110
不可逆な意思決定を避けながら10億超の顧客データを AI Ready にするデータ基盤設計
baseballyama
1
320
Metadata - Section 1: HTML Basics
mohab1
0
110
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
130
初対面のメンバーがチームを組み、Claude Codeでゼロからサービスをリリース
mkdev10
1
130
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
440
go-sqletch
moznion
0
140
フロントエンドカンファレンス関西2026 - 速すぎるUIに、待ち時間を
teamlab
PRO
0
110
1つのリクエストを追って理解する - llm-dのP/D分離
akhino
1
150
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
220
Post AI時代のリファクタリング実践記 / Refactoring in the post AI era
kaminashi
1
220
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
30 Presentation Tips
portentint
PRO
1
430
The Language of Interfaces
destraynor
162
27k
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
870
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Documentation Writing (for coders)
carmenintech
77
5.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Six Lessons from altMBA
skipperchong
29
4.5k
Odyssey Design
rkendrick25
PRO
2
870
Transcript
RxSwiftͰTwitterͷ ϥΠϒϥϦΛ࡞ͬͯΔ (͍͍ͩͨ)৽ଔΤϯδχΞ͚ٕज़ަྲྀձ vol.6 on 2016/03/12 @mihyaeru21
͓લɺ୭Α • ϛώϟΤϧ @mihyaeru21 • Swift͓͡͞Μ • Kotlin͓͡͞Μ • ͱ͖Ͳ͖PerlϚϯ
RxSwift + Twitter
RxTwift
RxTwift • RxSwiftϕʔε • ґଘؚΊͯSwiftͷΈ • ܕܕܕ • https://github.com/mihyaeru21/RxTwift
͖ͯͱ͏ͳઆ໌ • TwitterͷAPIͱରԠͨ͠ΠϯλϑΣʔε • ApiΫϥεɺ͍ͣΕRestApiʹ໊લ͕มΘΓͦ͏ let api = RxTwift.Api(…) api.get.statuses.homeTimeline()
GET /statuses/home_timeline
͖ͯͱ͏ͳઆ໌ • શͯͷAPIϝιουObservableΛฦ͢ api.get.statuses.homeTimeline() Observable<Tweet>
͖ͯͱ͏ͳઆ໌ • ObservableͷதJSONͰͳ͍ΦϒδΣΫτ api.get.statuses.homeTimeline() .subscribeNext { tweet in print("\(tweet.user.name)\n\(tweet.text)") }
͖ͯͱ͏ͳઆ໌ • ObservableͷதJSONͰͳ͍ΦϒδΣΫτ api.get.statuses.homeTimeline() .subscribeNext { tweet in print("\(tweet.user.name)\n\(tweet.text)") }
ίʔυิͰ͖Δͤʂʂʂ
ͪΐͬͱෳࡶͳྫ • ͋ΔϦετΛऔಘͯ͠ • ͦͷϦετͷϢʔβʢσϑΥϧτ20ਓʣ • ͷ͏ͪɺID͕ۮͷਓͷʢҙຯෆ໌ͳૢ࡞͚ͩͲྫ͔ͩΒڐͯ͠ʣ • λΠϜϥΠϯΛऔಘͯ͠ʢAPIΛୟ͖·͘Δʣ •
දࣔ
Θʔɺ͍͢͝
தͷ
தͷ • OAuth • ΦϒδΣΫτϚοϐϯά • Rx • ެ։APIϝιουͷྫ
OAuth • OAuthΛSwiftͰ࣮͍ͯ͠ΔϥΠϒϥϦ͋Δ • https://github.com/OAuthSwift/OAuthSwift • ͦΜͳʹଟػೳඞཁͳ͔ͬͨ • ετϦʔϛϯάʹରԠͰ͖ͳͦ͏ •
ͱ͍͏Θ͚Ͱࣗ࡞ • HMAC-SHA1͚ͩCryptoSwiftʹґଘ • https://github.com/krzyzanowskim/CryptoSwift • ඞཁͳػೳΑΓଟػೳ͗͢Δ͔Βґଘ͔Β֎͍ͨ͠
OAuth: ೝূͷϔομΛ࡞Δ෦
OAuth • Ϧετॲཧͱ͔จࣈྻॲཧ͕݁ʹॻ͖͍͢ • ʢൺֱରɿObjective-Cʣ • ྫ֎ॲཧnilΛฦ͚ͩ͢ͷखൈ͖ • खൈ͖͚ͩͲ͜Ε͘Β͍ͷॲཧʹे
ΦϒδΣΫτϚοϐϯά • Argo: https://github.com/thoughtbot/Argo • Swift͚ϥΠϒϥϦͰ࠷γϯϓϧʢͳίʔυʹͳΔ
ΦϒδΣΫτϚοϐϯά • README͔ΒҾ༻ struct User { let id: Int let
name: String let email: String? let role: Role let companyName: String let friends: [User] }
ΦϒδΣΫτϚοϐϯά • README͔ΒҾ༻ extension User: Decodable { static func decode(j:
JSON) -> Decoded<User> { return curry(User.init) <^> j <| "id" <*> j <| "name" <*> j <|? "email" <*> j <| "role" <*> j <| ["company", "name"] <*> j <|| "friends" } }
ΦϒδΣΫτϚοϐϯά • มͳه߸ͱ͔ʹ͍ͭͯྑ͍ղઆهࣄ͕͋Δ • http://qiita.com/koher/items/300d89136b515291dac4
ΦϒδΣΫτϚοϐϯά
ΦϒδΣΫτϚοϐϯά ͕ࣜෳࡶ͗ͯ͢ίϯύΠϧͰ͖Ͷʔ͔Β ׂͯͪ͠ΐ
ΦϒδΣΫτϚοϐϯά ࠅ͍͚Ͳಈ͘…
Rx • RxSwift • https://github.com/ReactiveX/RxSwift • ࠷ۙྲྀߦΓʁͷFRP • http://ninjinkun.hatenablog.com/entry/introrxja
Rx • Observable • 1ͭͷPromiseʹෳͷΛྲྀͤͯߴػೳԽͨ͠ײ͡ • ObservableΛ࡞ͬͨஈ֊ͰԿ͠ͳ͍ • ୭͔ʹsubscribe͞ΕΔ͜ͱʹΑͬͯىಈ
Rx: RxTwiftͰ • APIڞ௨ͷϦΫΤετൃߦ෦ • Observable<NSData>
Rx: RxTwiftͰ • JSONจࣈྻΛදݱ͢ΔNSDataΛσίʔυ • ArgoʹΑͬͯΦϒδΣΫτʹม • Observable<Tweet> • Observable<User>
• etc…
ެ։APIϝιουͷ࣮ྫ
ެ։APIϝιουͷ࣮ྫ
client.get(), client.post() • RxTwiftʹ͓͚ΔObservableͷݯྲྀ • Observable.create()ʹΑͬͯੜ • தෳࡶ͔ͩΒׂѪ
ެ։APIϝιουͷ࣮ྫ
Dictionary.createWithNotNil • nilͳཁૉΛল͍ͨDictionaryΛ࡞Δ
ެ։APIϝιουͷ࣮ྫ
Observable<Element>.decode()
ฦΓͷܕͰΦʔόʔϩʔυ ҧ͍͜Ε͚ͩ
ϚοϐϯάରͷܕฦΓ͔Βਪ
ϚοϐϯάରͷܕฦΓ͔Βਪ ͜ΕʹΑͬͯͲͷΦϒδΣΫτ ʹϚοϐϯά͢Δ͔ܾ·Δ
ϚοϐϯάରͷܕฦΓ͔Βਪ ͜ΕʹΑͬͯͲͷΦϒδΣΫτ ʹϚοϐϯά͢Δ͔ܾ·Δ
Observable<Element>.flatMapSequence() • Observable<[T]> Λ Observable<T> ʹม • ετϦʔϜͱͯ͠ѻ͍ͯ͘͢͠Δ • ʢ͜ͷมແ͔͘͢…ʣ
decode()ͷฦΓͷਪ • flatMapSequence() • Observable<[Tweet]> -> Observable<Tweet> • decode() •
Observable<NSData> -> Observable<[Tweet]>
ݱঢ়Ͱ͖͍ͯΔൣғ • OAuthೝূʹΑΔ௨৴ • GET/POST status/* ͷAPI • GET lists/*
ͷAPI • ࣮ࡁΈAPIͷϨεϙϯεʹରԠ͢ΔΦϒδΣΫτ • TwitterଆΤϥʔʹରԠ͢ΔΦϒδΣΫτ
ࠓޙ࣮͢Δൣғ • ೝূͷτʔΫϯऔಘॲཧ • ະ࣮ͷREST API • ετϦʔϛϯάAPI • ύϥϝʔλʹԠͯ͡ϨεϙϯεJSONͷߏ͕
มΘΔ͜ͱͷରԠ • ະ࣮ͷΦϒδΣΫτ