SlideShare a Scribd company logo
Extending Foundation
Swift Meetup Hamburg • 2016–09–21 • @herzi
Recap: Promises
createMagicPromise().then { reply in
if reply.response.statusCode != 200 {
throw RESTError.badResponse(reply.response)
}
// 🤔 : Still need to validate the content type.
return JSON.parse(data: reply.data)
}.then { json in
return User(serialized: json)
}.then { user in
// Do something with the user object.
}.fail { error in
// Don’t handle errors like this when being outside of keynote.
fatalError("FIXME: Handle error: (error)")
}.done()
URLSession + Promises
typealias Reply = (response: URLResponse,
data: Data)
// I really don’t have a better name.
protocol RESTful {
func get(url: URL) -> Promise<Reply>
}
URLSession
+Promise.swift
URLSession+Promise
extension URLSession: RESTful {
func get(url: URL) -> Promise<Reply> {
/* TODO: Use
* URLSession.dataTask(with:, completionHandler:)
*/
fatalError("Unimplemented.")
}
}
// Looks good, no?
URLSession+Promise
extension URLSession: RESTful {
func get(url: URL) -> Promise<Reply> {
/* TODO: Use
* URLSession.dataTask(with:, completionHandler:)
*/
fatalError("Unimplemented.")
}
}
// Looks good, no? No.
How to Test?
extension URLSession: RESTful {
func get(url: URL) -> Promise<Reply> {
/* TODO: Use
* URLSession.dataTask(with:, completionHandler:)
*/
fatalError("Unimplemented.")
}
}
// Looks good, no? No, I don’t want to set up an HTTP server.
Let’s try again
protocol URLSessionLike {
typealias Completion = (Data?, URLResponse?, Error?) -> Void
func dataTask(with url: URL,
completionHandler: @escaping Completion)
-> URLSessionDataTask
}
extension URLSession: URLSessionLike {}
Let’s try again (cont.)
protocol URLSessionLike: RESTful {
typealias Completion = (Data?, URLResponse?,
Error?) -> Void
func dataTask(with url: URL,
completionHandler: @escaping Completion)
-> URLSessionDataTask
}
extension URLSession: URLSessionLike {}



extension URLSessionLike {
func get(url: URL) -> Promise<Reply> {
fatalError("Still unimplemented.")
}
}
Testing the Protocol
class MockSession: URLSessionLike {
internal func dataTask(with url: URL,
completionHandler: @escaping
URLSessionLike.Completion)
-> URLSessionDataTask
{
DispatchQueue.main.async {
let error = URLError(.notConnectedToInternet)
completionHandler(nil, nil, error)
}
}
}
/* Later you will only mock RESTful things and return
* Promises directly. */
Questions?
Slides will be uploaded and linked in the Meetup Group

More Related Content

What's hot

Put a little Backbone in your WordPress
Put a little Backbone in your WordPressPut a little Backbone in your WordPress
Put a little Backbone in your WordPress
adamsilverstein
 
API Days Australia - Automatic Testing of (RESTful) API Documentation
API Days Australia  - Automatic Testing of (RESTful) API DocumentationAPI Days Australia  - Automatic Testing of (RESTful) API Documentation
API Days Australia - Automatic Testing of (RESTful) API Documentation
Rouven Weßling
 
Node.js Lightning Talk
Node.js Lightning TalkNode.js Lightning Talk
Node.js Lightning Talk
CodeSlice
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
Nina Zakharenko
 
JavaScript : A trending scripting language
JavaScript : A trending scripting languageJavaScript : A trending scripting language
JavaScript : A trending scripting language
AbhayDhupar
 
Gojko Adzic Cucumber
Gojko Adzic CucumberGojko Adzic Cucumber
Gojko Adzic Cucumber
Skills Matter
 
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
JSChannel 2017 - Service Workers and the Role they Play in modern day web-appsJSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
Mukul Jain
 
I18n
I18nI18n
I18nsoon
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Eventstkramar
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajaxbaygross
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with Gaelyk
Choong Ping Teo
 
React Under the Hood: Understanding React's UI Rendering Process
React Under the Hood: Understanding React's UI Rendering ProcessReact Under the Hood: Understanding React's UI Rendering Process
React Under the Hood: Understanding React's UI Rendering Process
Anthony Garritano
 
Effective Testing using Behavior-Driven Development
Effective Testing using Behavior-Driven DevelopmentEffective Testing using Behavior-Driven Development
Effective Testing using Behavior-Driven Development
Alexander Kress
 

What's hot (14)

Put a little Backbone in your WordPress
Put a little Backbone in your WordPressPut a little Backbone in your WordPress
Put a little Backbone in your WordPress
 
API Days Australia - Automatic Testing of (RESTful) API Documentation
API Days Australia  - Automatic Testing of (RESTful) API DocumentationAPI Days Australia  - Automatic Testing of (RESTful) API Documentation
API Days Australia - Automatic Testing of (RESTful) API Documentation
 
Node.js Lightning Talk
Node.js Lightning TalkNode.js Lightning Talk
Node.js Lightning Talk
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
JavaScript : A trending scripting language
JavaScript : A trending scripting languageJavaScript : A trending scripting language
JavaScript : A trending scripting language
 
Gojko Adzic Cucumber
Gojko Adzic CucumberGojko Adzic Cucumber
Gojko Adzic Cucumber
 
Ruby de Rails
Ruby de RailsRuby de Rails
Ruby de Rails
 
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
JSChannel 2017 - Service Workers and the Role they Play in modern day web-appsJSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
JSChannel 2017 - Service Workers and the Role they Play in modern day web-apps
 
I18n
I18nI18n
I18n
 
Live Streaming & Server Sent Events
Live Streaming & Server Sent EventsLive Streaming & Server Sent Events
Live Streaming & Server Sent Events
 
Week 4 - jQuery + Ajax
Week 4 - jQuery + AjaxWeek 4 - jQuery + Ajax
Week 4 - jQuery + Ajax
 
Google App Engine with Gaelyk
Google App Engine with GaelykGoogle App Engine with Gaelyk
Google App Engine with Gaelyk
 
React Under the Hood: Understanding React's UI Rendering Process
React Under the Hood: Understanding React's UI Rendering ProcessReact Under the Hood: Understanding React's UI Rendering Process
React Under the Hood: Understanding React's UI Rendering Process
 
Effective Testing using Behavior-Driven Development
Effective Testing using Behavior-Driven DevelopmentEffective Testing using Behavior-Driven Development
Effective Testing using Behavior-Driven Development
 

Viewers also liked

IRS Tax Tips for Year End Gifts to Charity
IRS Tax Tips for Year End Gifts to CharityIRS Tax Tips for Year End Gifts to Charity
IRS Tax Tips for Year End Gifts to Charity
Tax Assistance Group
 
พระไตรปิฎกฉบับหลวงเล่มที่๐๘
พระไตรปิฎกฉบับหลวงเล่มที่๐๘พระไตรปิฎกฉบับหลวงเล่มที่๐๘
พระไตรปิฎกฉบับหลวงเล่มที่๐๘Rose Banioki
 
Moose Hunting in Alaska BOW Presentation 2016
Moose Hunting in Alaska BOW Presentation 2016Moose Hunting in Alaska BOW Presentation 2016
Moose Hunting in Alaska BOW Presentation 2016Becky Schwanke
 
Catalogo corsi di formazione The Energy Audit 2014
Catalogo corsi di formazione The Energy Audit 2014Catalogo corsi di formazione The Energy Audit 2014
Catalogo corsi di formazione The Energy Audit 2014
TheEnergyAudit
 
5 Tax Breaks For Entrepreneurs
5 Tax Breaks For Entrepreneurs5 Tax Breaks For Entrepreneurs
5 Tax Breaks For Entrepreneurs
Tax Defense Network
 
diapositiva 2
diapositiva 2diapositiva 2
diapositiva 2
lunaparraquince
 
Transforamções de unidades
Transforamções de unidadesTransforamções de unidades
Transforamções de unidades
Luciana Oliveira
 
พระไตรปิฎกฉบับหลวงเล่มที่๐๙
พระไตรปิฎกฉบับหลวงเล่มที่๐๙พระไตรปิฎกฉบับหลวงเล่มที่๐๙
พระไตรปิฎกฉบับหลวงเล่มที่๐๙Rose Banioki
 
Catalogo Navideño Colombina Guatemala 2015, en Comprabien Foodservice, PBX 24...
Catalogo Navideño Colombina Guatemala 2015, en Comprabien Foodservice, PBX 24...Catalogo Navideño Colombina Guatemala 2015, en Comprabien Foodservice, PBX 24...
Catalogo Navideño Colombina Guatemala 2015, en Comprabien Foodservice, PBX 24...
COMPRAbién Food Service de Guatemala, PBX 24730581
 
Hablemos Sin Tapujos.
Hablemos Sin Tapujos.Hablemos Sin Tapujos.
Hablemos Sin Tapujos.
alejandra1zapeta
 
Inclusive growth
Inclusive growthInclusive growth
Inclusive growth
Samikshya Kar
 
Accomodation
AccomodationAccomodation
Accomodation
SSSIHMS-PG
 

Viewers also liked (16)

IRS Tax Tips for Year End Gifts to Charity
IRS Tax Tips for Year End Gifts to CharityIRS Tax Tips for Year End Gifts to Charity
IRS Tax Tips for Year End Gifts to Charity
 
พระไตรปิฎกฉบับหลวงเล่มที่๐๘
พระไตรปิฎกฉบับหลวงเล่มที่๐๘พระไตรปิฎกฉบับหลวงเล่มที่๐๘
พระไตรปิฎกฉบับหลวงเล่มที่๐๘
 
1,SARAD Resume
1,SARAD Resume1,SARAD Resume
1,SARAD Resume
 
Team work jueves 5.00-7.00 pm
Team work  jueves 5.00-7.00 pmTeam work  jueves 5.00-7.00 pm
Team work jueves 5.00-7.00 pm
 
Moose Hunting in Alaska BOW Presentation 2016
Moose Hunting in Alaska BOW Presentation 2016Moose Hunting in Alaska BOW Presentation 2016
Moose Hunting in Alaska BOW Presentation 2016
 
Catalogo corsi di formazione The Energy Audit 2014
Catalogo corsi di formazione The Energy Audit 2014Catalogo corsi di formazione The Energy Audit 2014
Catalogo corsi di formazione The Energy Audit 2014
 
5 Tax Breaks For Entrepreneurs
5 Tax Breaks For Entrepreneurs5 Tax Breaks For Entrepreneurs
5 Tax Breaks For Entrepreneurs
 
014
014014
014
 
diapositiva 2
diapositiva 2diapositiva 2
diapositiva 2
 
Y
YY
Y
 
Transforamções de unidades
Transforamções de unidadesTransforamções de unidades
Transforamções de unidades
 
พระไตรปิฎกฉบับหลวงเล่มที่๐๙
พระไตรปิฎกฉบับหลวงเล่มที่๐๙พระไตรปิฎกฉบับหลวงเล่มที่๐๙
พระไตรปิฎกฉบับหลวงเล่มที่๐๙
 
Catalogo Navideño Colombina Guatemala 2015, en Comprabien Foodservice, PBX 24...
Catalogo Navideño Colombina Guatemala 2015, en Comprabien Foodservice, PBX 24...Catalogo Navideño Colombina Guatemala 2015, en Comprabien Foodservice, PBX 24...
Catalogo Navideño Colombina Guatemala 2015, en Comprabien Foodservice, PBX 24...
 
Hablemos Sin Tapujos.
Hablemos Sin Tapujos.Hablemos Sin Tapujos.
Hablemos Sin Tapujos.
 
Inclusive growth
Inclusive growthInclusive growth
Inclusive growth
 
Accomodation
AccomodationAccomodation
Accomodation
 

Similar to Swift Meetup HH 2016/09

async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
Peter Friese
 
Progressive Enhancment with Rails and React
Progressive Enhancment with Rails and ReactProgressive Enhancment with Rails and React
Progressive Enhancment with Rails and React
Tyler Johnston
 
TPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and FluxTPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and Flux
Jirat Kijlerdpornpailoj
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
Adam Klein
 
Koajs as an alternative to Express - OdessaJs'16
Koajs as an alternative to Express - OdessaJs'16Koajs as an alternative to Express - OdessaJs'16
Koajs as an alternative to Express - OdessaJs'16
Nikolay Kozhukharenko
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
Andy McKay
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React Native
Software Guru
 
Itjsf13
Itjsf13Itjsf13
Itjsf13
Thinkful
 
Building a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsBuilding a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.js
Nicolas Hery
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
rstankov
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
David Furber
 
Advanced Javascript Unit Testing
Advanced Javascript Unit TestingAdvanced Javascript Unit Testing
Advanced Javascript Unit Testing
Lars Thorup
 
REST more with json-api and fractal
REST more with json-api and fractalREST more with json-api and fractal
REST more with json-api and fractal
Boyan Yordanov
 
Itjsf13
Itjsf13Itjsf13
Itjsf13
Thinkful
 
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JSFestUA
 
Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017
Jens Ravens
 
The Exciting Future Of React
The Exciting Future Of ReactThe Exciting Future Of React
The Exciting Future Of React
kristijanmkd
 
Ba Node.js Meetup React Native Presentation
Ba Node.js Meetup React Native PresentationBa Node.js Meetup React Native Presentation
Ba Node.js Meetup React Native Presentation
Gustavo Machado
 

Similar to Swift Meetup HH 2016/09 (20)

async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Progressive Enhancment with Rails and React
Progressive Enhancment with Rails and ReactProgressive Enhancment with Rails and React
Progressive Enhancment with Rails and React
 
Itjsf320
Itjsf320Itjsf320
Itjsf320
 
huhu
huhuhuhu
huhu
 
TPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and FluxTPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and Flux
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
 
Koajs as an alternative to Express - OdessaJs'16
Koajs as an alternative to Express - OdessaJs'16Koajs as an alternative to Express - OdessaJs'16
Koajs as an alternative to Express - OdessaJs'16
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React Native
 
Itjsf13
Itjsf13Itjsf13
Itjsf13
 
Building a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.jsBuilding a website in Haskell coming from Node.js
Building a website in Haskell coming from Node.js
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Advanced Javascript Unit Testing
Advanced Javascript Unit TestingAdvanced Javascript Unit Testing
Advanced Javascript Unit Testing
 
REST more with json-api and fractal
REST more with json-api and fractalREST more with json-api and fractal
REST more with json-api and fractal
 
Itjsf13
Itjsf13Itjsf13
Itjsf13
 
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
JS Fest 2019. Glenn Reyes. With great power comes great React hooks!
 
Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017Server Side Swift - AppBuilders 2017
Server Side Swift - AppBuilders 2017
 
The Exciting Future Of React
The Exciting Future Of ReactThe Exciting Future Of React
The Exciting Future Of React
 
Ba Node.js Meetup React Native Presentation
Ba Node.js Meetup React Native PresentationBa Node.js Meetup React Native Presentation
Ba Node.js Meetup React Native Presentation
 

Recently uploaded

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
kalichargn70th171
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 

Recently uploaded (20)

Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
Why Mobile App Regression Testing is Critical for Sustained Success_ A Detail...
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 

Swift Meetup HH 2016/09

  • 1. Extending Foundation Swift Meetup Hamburg • 2016–09–21 • @herzi
  • 2. Recap: Promises createMagicPromise().then { reply in if reply.response.statusCode != 200 { throw RESTError.badResponse(reply.response) } // 🤔 : Still need to validate the content type. return JSON.parse(data: reply.data) }.then { json in return User(serialized: json) }.then { user in // Do something with the user object. }.fail { error in // Don’t handle errors like this when being outside of keynote. fatalError("FIXME: Handle error: (error)") }.done()
  • 3. URLSession + Promises typealias Reply = (response: URLResponse, data: Data) // I really don’t have a better name. protocol RESTful { func get(url: URL) -> Promise<Reply> }
  • 5. URLSession+Promise extension URLSession: RESTful { func get(url: URL) -> Promise<Reply> { /* TODO: Use * URLSession.dataTask(with:, completionHandler:) */ fatalError("Unimplemented.") } } // Looks good, no?
  • 6. URLSession+Promise extension URLSession: RESTful { func get(url: URL) -> Promise<Reply> { /* TODO: Use * URLSession.dataTask(with:, completionHandler:) */ fatalError("Unimplemented.") } } // Looks good, no? No.
  • 7. How to Test? extension URLSession: RESTful { func get(url: URL) -> Promise<Reply> { /* TODO: Use * URLSession.dataTask(with:, completionHandler:) */ fatalError("Unimplemented.") } } // Looks good, no? No, I don’t want to set up an HTTP server.
  • 8. Let’s try again protocol URLSessionLike { typealias Completion = (Data?, URLResponse?, Error?) -> Void func dataTask(with url: URL, completionHandler: @escaping Completion) -> URLSessionDataTask } extension URLSession: URLSessionLike {}
  • 9. Let’s try again (cont.) protocol URLSessionLike: RESTful { typealias Completion = (Data?, URLResponse?, Error?) -> Void func dataTask(with url: URL, completionHandler: @escaping Completion) -> URLSessionDataTask } extension URLSession: URLSessionLike {}
 
 extension URLSessionLike { func get(url: URL) -> Promise<Reply> { fatalError("Still unimplemented.") } }
  • 10. Testing the Protocol class MockSession: URLSessionLike { internal func dataTask(with url: URL, completionHandler: @escaping URLSessionLike.Completion) -> URLSessionDataTask { DispatchQueue.main.async { let error = URLError(.notConnectedToInternet) completionHandler(nil, nil, error) } } } /* Later you will only mock RESTful things and return * Promises directly. */
  • 11. Questions? Slides will be uploaded and linked in the Meetup Group