SlideShare a Scribd company logo
1 of 33
Download to read offline
CONCURRENT NETWORKING
     – MADE EASY!
   CocoaHeads Stockholm, March 5 2012
        MARTHIN FREIJ / AMAZING APPLICATIONS
AMAZING APPLICATIONS / IN SHORT
A two-man army of digital production
veterans, on a crusade to delight people
with pixel perfect design, delicate code
and stunning user experiences.

We work hard to ensure that everything
from concept and user interaction design
to animations and technical
implementation is as sleek as possible.
MARTHIN FREIJ / SENIOR DEVELOPER             JIMMY POOPUU / ART DIRECTOR
Has written million lines of code as a       A tech savvy pixel pusher and design geek
software developer and held countless        with over 15 years of experience working
lectures as technical trainer during the     with global brands in digital channels.
past 10 years for clients in the bank,       Also a confused father and a avid gamer.
finance and media sector.
                                             CLIENT SHORT LIST:
CLIENT SHORT LIST:                           Vin & Sprit (Absolut Vodka & Malibu Rum), IKEA,
ICA Banken, Handelsbanken, Bonnier, Dagens   Scania, Electrolux, Nokia, SCA (Libresse)
Nyheter, Dagens Industri
NJUICE   WKLY   GREEN KITCHEN
CONCURRENT NETWORKING
     – MADE EASY!
   CocoaHeads Stockholm, March 5 2012
        MARTHIN FREIJ / AMAZING APPLICATIONS
MADE EASY?
IS IT HARD
IN THE FIRST PLACE?
APPLE PROVIDE SIMPLE
API’S FOR NETWORKING
NSURLConnection
NSURLRequest
NSURLResponse
;(
FEW DEVELOPERS USE THEM
BECAUSE THEY REQUIRE
 A LOT OF BOILERPLATE CODE
- (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate;

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
AND MAYBE YOU WANT TO DO
 MORE THAN ONE REQUEST
      AT THE TIME?
THEN YOU NEED TO
   KEEP TRACK
OF YOUR REQUESTS
AND CONNECTIONS
WE TEND TO USE BOILERPLATE CODE
    WRITTEN BY SOMEONE ELSE
LIKE NETWORK LIBRARIES
ASIHTTPREQUEST
DOH! DISCONTINUED!
AFNETWORKING
!
     BUGS!
RACE CONDITIONS!
 MEMORY LEAKS!
IT TURNS OUT
TO BE KIND OF HARD
NEW STUFF IN iOS 5
+ (void)sendAsynchronousRequest:(NSURLRequest *)request
              queue:(NSOperationQueue*) queue
        completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*)) handler;
☞ NSURLRequest
☞ NSOperationQueue
☞ Completion Handler
// Create the request
NSURL *url = [NSURL URLWithString:@"https://the.api.com/method/"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

// Create the queue
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.name = @"com.your.unique.queue.name";

[NSURLConnection sendAsynchronousRequest:request
                 queue:queue
          completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

      // If there was an error getting the data
      if (error) {
          dispatch_async(dispatch_get_main_queue(), ^(void) {
              // Display error message in UI
          });
          return;
      }

      // Do stuff with the data

      dispatch_async(dispatch_get_main_queue(), ^(void) {
          // Update UI
      });
}];
ONE MORE THING...
CORE DATA AND CONCURRENCY HAVEN’T
     ALWAYS BEEN BEST BUDDIES
UNTIL NOW IN iOS 5
NSManagedObjectContext
- (id)initWithConcurrencyType:(NSManagedObjectContextConcurrencyType)ct;
- (void)setParentContext:(NSManagedObjectContext*)parent;
- (void)performBlock:(void (^)())block;
IMPORT DATA EXAMPLE (1 / 2)
☞   Set your main context to execute on Main Queue
     (NSMainQueueConcurrencyType)

☞   Create an import context and tell Core Data to create a new
    queue for it (NSPrivateQueueConcurrencyType)

☞   Set the main context as the import contexts parentContext
IMPORT DATA EXAMPLE (2 / 2)
☞   On the import context, call performBlock and do the import (i.e.
    download data, validate it, import it, purge old data etc)

☞   Save changes on the import context. This will stage it up one
    level (to the main context)

☞   Save changes on the main context. This will persist it on the
    associated persistent store (and update
    NSFetchedResultControllers etc)
// Setup the main context (probably in the AppDelegate)
[[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
NSManagedObjectContext *importContext =
  [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];

importContext.parentContext = self.managedObjectContext;

[importContext performBlock:^{

      // Download data, import etc..

      NSError *importError = nil;
      [importContext save:&importError];

      [importContext.parentContext performBlock:^{
          NSError *parentError = nil;
          [importContext.parentContext save:&parentError];
      }];
}];
THATS IT, THANKS FOR YOUR TIME!
       www.amazing-apps.se

More Related Content

What's hot

Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tCosimo Streppone
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Dotan Dimet
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and othersYusuke Wada
 

What's hot (6)

Socket.IO
Socket.IOSocket.IO
Socket.IO
 
Mojolicious: what works and what doesn't
Mojolicious: what works and what doesn'tMojolicious: what works and what doesn't
Mojolicious: what works and what doesn't
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 
Socket.io (part 1)
Socket.io (part 1)Socket.io (part 1)
Socket.io (part 1)
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 

Similar to Concurrent networking - made easy

Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps OfflinePedro Morais
 
Data Access Mobile Devices
Data Access Mobile DevicesData Access Mobile Devices
Data Access Mobile Devicesvenkat987
 
Simple callcenter platform with PHP
Simple callcenter platform with PHPSimple callcenter platform with PHP
Simple callcenter platform with PHPMorten Amundsen
 
Endless Possibilities: Building a Customer360 with Neo4j, Structr, and Vendor...
Endless Possibilities: Building a Customer360 with Neo4j, Structr, and Vendor...Endless Possibilities: Building a Customer360 with Neo4j, Structr, and Vendor...
Endless Possibilities: Building a Customer360 with Neo4j, Structr, and Vendor...Neo4j
 
Electron Firenze 2020: Linux, Windows o MacOS?
Electron Firenze 2020: Linux, Windows o MacOS?Electron Firenze 2020: Linux, Windows o MacOS?
Electron Firenze 2020: Linux, Windows o MacOS?Denny Biasiolli
 
Electron: Linux, Windows or Macos?
Electron: Linux, Windows or Macos?Electron: Linux, Windows or Macos?
Electron: Linux, Windows or Macos?Commit University
 
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdfJava Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdfSudhanshiBakre1
 
RedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedis Labs
 
iPhone and Rails integration
iPhone and Rails integrationiPhone and Rails integration
iPhone and Rails integrationPaul Ardeleanu
 
maxbox starter72 multilanguage coding
maxbox starter72 multilanguage codingmaxbox starter72 multilanguage coding
maxbox starter72 multilanguage codingMax Kleiner
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqelajobandesther
 
Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...
Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...
Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...Athens IoT Meetup
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyUlrich Krause
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Windows Developer
 
WebLogic Administration und Deployment mit WLST
WebLogic Administration und Deployment mit WLSTWebLogic Administration und Deployment mit WLST
WebLogic Administration und Deployment mit WLSTenpit GmbH & Co. KG
 
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios
 
OpenCL Programming 101
OpenCL Programming 101OpenCL Programming 101
OpenCL Programming 101Yoss Cohen
 

Similar to Concurrent networking - made easy (20)

Introduction to Node MCU
Introduction to Node MCUIntroduction to Node MCU
Introduction to Node MCU
 
Taking Web Apps Offline
Taking Web Apps OfflineTaking Web Apps Offline
Taking Web Apps Offline
 
Data Access Mobile Devices
Data Access Mobile DevicesData Access Mobile Devices
Data Access Mobile Devices
 
Simple callcenter platform with PHP
Simple callcenter platform with PHPSimple callcenter platform with PHP
Simple callcenter platform with PHP
 
Endless Possibilities: Building a Customer360 with Neo4j, Structr, and Vendor...
Endless Possibilities: Building a Customer360 with Neo4j, Structr, and Vendor...Endless Possibilities: Building a Customer360 with Neo4j, Structr, and Vendor...
Endless Possibilities: Building a Customer360 with Neo4j, Structr, and Vendor...
 
Electron Firenze 2020: Linux, Windows o MacOS?
Electron Firenze 2020: Linux, Windows o MacOS?Electron Firenze 2020: Linux, Windows o MacOS?
Electron Firenze 2020: Linux, Windows o MacOS?
 
Electron: Linux, Windows or Macos?
Electron: Linux, Windows or Macos?Electron: Linux, Windows or Macos?
Electron: Linux, Windows or Macos?
 
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdfJava Airline Reservation System – Travel Smarter, Not Harder.pdf
Java Airline Reservation System – Travel Smarter, Not Harder.pdf
 
RedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis code
 
iPhone and Rails integration
iPhone and Rails integrationiPhone and Rails integration
iPhone and Rails integration
 
maxbox starter72 multilanguage coding
maxbox starter72 multilanguage codingmaxbox starter72 multilanguage coding
maxbox starter72 multilanguage coding
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
 
Always on! Or not?
Always on! Or not?Always on! Or not?
Always on! Or not?
 
Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...
Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...
Athens IoT meetup #7 - Create the Internet of your Things - Laurent Ellerbach...
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
Electron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easyElectron - cross platform desktop applications made easy
Electron - cross platform desktop applications made easy
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
 
WebLogic Administration und Deployment mit WLST
WebLogic Administration und Deployment mit WLSTWebLogic Administration und Deployment mit WLST
WebLogic Administration und Deployment mit WLST
 
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being LazyNagios Conference 2012 - Dave Josephsen - Stop Being Lazy
Nagios Conference 2012 - Dave Josephsen - Stop Being Lazy
 
OpenCL Programming 101
OpenCL Programming 101OpenCL Programming 101
OpenCL Programming 101
 

Recently uploaded

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

Concurrent networking - made easy

  • 1. CONCURRENT NETWORKING – MADE EASY! CocoaHeads Stockholm, March 5 2012 MARTHIN FREIJ / AMAZING APPLICATIONS
  • 2.
  • 3. AMAZING APPLICATIONS / IN SHORT A two-man army of digital production veterans, on a crusade to delight people with pixel perfect design, delicate code and stunning user experiences. We work hard to ensure that everything from concept and user interaction design to animations and technical implementation is as sleek as possible.
  • 4. MARTHIN FREIJ / SENIOR DEVELOPER JIMMY POOPUU / ART DIRECTOR Has written million lines of code as a A tech savvy pixel pusher and design geek software developer and held countless with over 15 years of experience working lectures as technical trainer during the with global brands in digital channels. past 10 years for clients in the bank, Also a confused father and a avid gamer. finance and media sector. CLIENT SHORT LIST: CLIENT SHORT LIST: Vin & Sprit (Absolut Vodka & Malibu Rum), IKEA, ICA Banken, Handelsbanken, Bonnier, Dagens Scania, Electrolux, Nokia, SCA (Libresse) Nyheter, Dagens Industri
  • 5. NJUICE WKLY GREEN KITCHEN
  • 6. CONCURRENT NETWORKING – MADE EASY! CocoaHeads Stockholm, March 5 2012 MARTHIN FREIJ / AMAZING APPLICATIONS
  • 7. MADE EASY? IS IT HARD IN THE FIRST PLACE?
  • 11. BECAUSE THEY REQUIRE A LOT OF BOILERPLATE CODE - (id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate; - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response; - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data; - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error; - (void)connectionDidFinishLoading:(NSURLConnection *)connection;
  • 12. AND MAYBE YOU WANT TO DO MORE THAN ONE REQUEST AT THE TIME?
  • 13. THEN YOU NEED TO KEEP TRACK OF YOUR REQUESTS AND CONNECTIONS
  • 14. WE TEND TO USE BOILERPLATE CODE WRITTEN BY SOMEONE ELSE
  • 19. ! BUGS! RACE CONDITIONS! MEMORY LEAKS!
  • 20. IT TURNS OUT TO BE KIND OF HARD
  • 21. NEW STUFF IN iOS 5
  • 22. + (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue*) queue completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*)) handler;
  • 24. // Create the request NSURL *url = [NSURL URLWithString:@"https://the.api.com/method/"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; // Create the queue NSOperationQueue *queue = [[NSOperationQueue alloc] init]; queue.name = @"com.your.unique.queue.name"; [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { // If there was an error getting the data if (error) { dispatch_async(dispatch_get_main_queue(), ^(void) { // Display error message in UI }); return; } // Do stuff with the data dispatch_async(dispatch_get_main_queue(), ^(void) { // Update UI }); }];
  • 26. CORE DATA AND CONCURRENCY HAVEN’T ALWAYS BEEN BEST BUDDIES
  • 27. UNTIL NOW IN iOS 5
  • 29. IMPORT DATA EXAMPLE (1 / 2) ☞ Set your main context to execute on Main Queue (NSMainQueueConcurrencyType) ☞ Create an import context and tell Core Data to create a new queue for it (NSPrivateQueueConcurrencyType) ☞ Set the main context as the import contexts parentContext
  • 30. IMPORT DATA EXAMPLE (2 / 2) ☞ On the import context, call performBlock and do the import (i.e. download data, validate it, import it, purge old data etc) ☞ Save changes on the import context. This will stage it up one level (to the main context) ☞ Save changes on the main context. This will persist it on the associated persistent store (and update NSFetchedResultControllers etc)
  • 31. // Setup the main context (probably in the AppDelegate) [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
  • 32. NSManagedObjectContext *importContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; importContext.parentContext = self.managedObjectContext; [importContext performBlock:^{ // Download data, import etc.. NSError *importError = nil; [importContext save:&importError]; [importContext.parentContext performBlock:^{ NSError *parentError = nil; [importContext.parentContext save:&parentError]; }]; }];
  • 33. THATS IT, THANKS FOR YOUR TIME! www.amazing-apps.se