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
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
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.1k
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6k
AgentCoreとHuman in the Loop
har1101
5
230
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
Data-Centric Kaggle
isax1015
2
770
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
120
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
高速開発のためのコード整理術
sutetotanuki
1
400
Architectural Extensions
denyspoltorak
0
280
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
120
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
A designer walks into a library…
pauljervisheath
210
24k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
How STYLIGHT went responsive
nonsquared
100
6k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
940
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
240
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Test your architecture with Archunit
thirion
1
2.1k
Utilizing Notion as your number one productivity tool
mfonobong
3
220
Facilitating Awesome Meetings
lara
57
6.8k
How to Ace a Technical Interview
jacobian
281
24k
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