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
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.5k
白金鉱業Meetup Vol.25 アウトカムが二値のデータに対するCausal Impact
brainpadpr
0
270
Genieを崇めよ
kameitomohiro
0
170
Antigravity SDK for the Java Developer
glaforge
0
170
おい、エージェントを使って終わらせろ
nwiizo
2
850
俺の仕事は AIに奪われないし、たぶんその BIも要らない
hikaruri
0
540
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
30
18k
「ピッケル本」日本語版は4.0(第6版)が出版されるべき / pickaxe4-nagoyark05
kakutani
2
270
リアーキテクチャ後の障害ゼロを目指したShadow Testingの取り組み
nihonbuson
PRO
1
170
What the customer really needed
kawaguti
PRO
3
220
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
2.3k
越境するなら専門用語を使うな高校校歌 / If you wanna cross border, you shouldn't use jargon
vtryo
0
150
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
410
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
340
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
Unsuck your backbone
ammeep
672
58k
Evolving SEO for Evolving Search Engines
ryanjones
0
300
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
530
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
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ͷߏ͕
มΘΔ͜ͱͷରԠ • ະ࣮ͷΦϒδΣΫτ