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
The Young Rappel
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Sergio Fernández
July 05, 2017
Programming
0
34
The Young Rappel
Futures and Promises on Swift
Sergio Fernández
July 05, 2017
Tweet
Share
More Decks by Sergio Fernández
See All by Sergio Fernández
Zero To Hero
fdzsergio
1
60
Other Decks in Programming
See All in Programming
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.4k
AI時代の認知負荷との向き合い方
optfit
0
160
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
720
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
230
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
950
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
Fluid Templating in TYPO3 14
s2b
0
130
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
99
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
410
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
64
How to Think Like a Performance Engineer
csswizardry
28
2.4k
For a Future-Friendly Web
brad_frost
182
10k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
250
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
110
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
52k
The Pragmatic Product Professional
lauravandoore
37
7.1k
Designing for humans not robots
tammielis
254
26k
Transcript
The Young Rappel Futures & Promises
Hi! I'm Sergio @fdzsergio
Agenda Working with asynchronous tasks Deferred computations Back to the
Future
Async is hard
Request Image login(with: credentials) { (result: JSONResponse) in if case
.success(let json) = result, let user = User(with: json) { fetch(avatar: user.avatarURL) { (result: DataResponse) in if case .success(let data) = result { let image = UIImage(data: data) self.imageView = UIImageView(image: image) } } } }
then
Request Image login(with: credentials) .then(User.init) .then { user in return
fetch(avatar: user.avatarURL) }.then { data in self.imageView.image = UIImage(data: data) }.catch { error in // handle error } }
Futures & Promises It is the way to handle complex
asynchronous operations in a simple way
What the heck is a Future?
Future is an object that represents that you will get
something in the future.
Future let login: Promise<User> = login(with: credentials) login.then { user
in self.storage.save(user) }
What is a Promise?
A promise is an object that may produce a single
value some time in the future
Promise func login(with credentials: Credentials) -> Promise<User> { return Promise
{ fulfill, reject in self.client.request(task: .login(credentials)) { result in switch result { case .success(let json): fulfill(User(with: json)) case .failure(let error): reject(error) } } } }
Common Functions → then → catch → always → when
→ all
Limitations of Futures → Promises can only produce one value
→ Can nwot encapsulate streams of values → Only consumer driven
Back to the Future → Abstraction for async/sync operations →
Encapsulate a deferred computation → Centralized error handling → Easily composable
DeLorean
B-Sides → https://promisesaplus.com → http://khanlou.com/2016/08/promises-in-swift → https://speakerdeck.com/javisoto/back-to-the- futures → https://medium.com/compileswift/hydra-
promises-swift-c6319f6a6209
The Future is Today. — William Osler
Thank You!
Questions? @fdzsergio