SlideShare a Scribd company logo
1 of 11
Download to read offline
AFNetworking	
  vs.	
  Na2ve	
  
NSURLConnec2on	
  &	
  	
  
NSURLSession	
  
+	
  Caching	
  
What	
  is	
  AFNetworking?	
  
AFNetworking	
  is	
  a	
  class	
  developed	
  by	
  MaD	
  Thompson	
  and	
  ScoD	
  Raymond	
  and	
  is	
  
described	
  as	
  “a	
  delighHul	
  networking	
  library	
  for	
  iOS	
  and	
  Mac	
  OS	
  X.”	
  It	
  makes	
  
common	
  tasks	
  like	
  asynchronous	
  hDp	
  requests	
  a	
  lot	
  easier.	
  	
  
AFNetworking	
  just	
  like	
  all	
  other	
  popular	
  libraries	
  to	
  do	
  the	
  same	
  all	
  use	
  
NSURLConnec2on	
  to	
  do	
  the	
  actual	
  'work'.	
  They	
  just	
  include	
  a	
  bunch	
  of	
  friendly	
  
methods	
  so	
  you	
  can	
  easily	
  make	
  requests	
  without	
  having	
  to	
  write	
  a	
  whole	
  lot	
  of	
  
boilerplate	
  code	
  yourself.	
  
Several	
  AFNetworking	
  benefits	
  
	
  -­‐	
  One	
  of	
  the	
  benefits	
  of	
  using	
  AFNetworking	
  is	
  the	
  data	
  type	
  classes	
  for	
  handling	
  
response	
  data.	
  The	
  success	
  block	
  has	
  already	
  parsed	
  the	
  response	
  and	
  returns	
  the	
  
data	
  for	
  you.	
  With	
  NSURLSession	
  you	
  receive	
  NSData	
  back	
  in	
  the	
  comple2on	
  
handler,	
  so	
  you	
  would	
  need	
  to	
  convert	
  the	
  NSData	
  into	
  JSON	
  or	
  other	
  formats.	
  
	
  -­‐	
  It	
  also	
  helps	
  you	
  ensure	
  that	
  your	
  UI	
  is	
  responsive	
  even	
  when	
  your	
  app	
  is	
  in	
  the	
  
middle	
  of	
  a	
  big	
  download.	
  
	
  -­‐	
  AFNetworking	
  adds	
  a	
  category	
  to	
  UIImageView	
  that	
  lets	
  you	
  load	
  images	
  
asynchronously,	
  meaning	
  the	
  UI	
  will	
  remain	
  responsive	
  while	
  images	
  are	
  
downloaded	
  in	
  the	
  background.	
  
What	
  is	
  NSURLSession?	
  
In	
  iOS	
  7,	
  Apple	
  has	
  introduced	
  NSURLSession,	
  which	
  is	
  a	
  suite	
  of	
  classes	
  that	
  replaces	
  
NSURLConnec-on	
  as	
  the	
  preferred	
  method	
  of	
  networking.	
  
Using	
  NSURLSession	
  is	
  just	
  as	
  easy	
  as	
  using	
  its	
  predecessor	
  NSURLConnec-on	
  for	
  
simple	
  tasks.	
  
Several	
  NSURLSession	
  new	
  advantages	
  and	
  benefits	
  
	
  
	
  -­‐	
  NSURLSession	
  is	
  created,	
  you	
  get	
  all	
  the	
  benefits	
  of	
  background	
  networking.	
  This	
  helps	
  
with	
  baDery	
  life,	
  supports	
  UIKit	
  mul2tasking	
  and	
  uses	
  the	
  same	
  delegate	
  model	
  as	
  in-­‐
process	
  transfers.	
  
	
  -­‐	
  Ability	
  to	
  pause	
  and	
  resume	
  networking	
  opera-ons:	
  With	
  the	
  NSURLSession	
  API	
  any	
  
networking	
  task	
  can	
  be	
  paused,	
  stopped,	
  and	
  restarted.	
  No	
  NSOpera2on	
  sub-­‐classing	
  is	
  
necessary.	
  
	
  -­‐	
  Instead	
  of	
  storing	
  all	
  of	
  the	
  networking	
  objects	
  (such	
  as	
  a	
  response	
  cache)	
  globally,	
  
NSURLSession	
  provides	
  a	
  mechanism	
  for	
  storing	
  objects	
  either	
  on	
  a	
  global	
  basis	
  or	
  on	
  a	
  
per	
  session	
  basis.	
  
 
	
  -­‐	
  Rich	
  delegate	
  model:	
  NSURLConnec-on	
  has	
  some	
  asynchronous	
  block	
  based	
  methods,	
  
however	
  a	
  delegate	
  cannot	
  be	
  used	
  with	
  them.	
  When	
  the	
  request	
  is	
  made	
  it	
  either	
  works	
  
or	
  fails,	
  even	
  if	
  authen2ca2on	
  was	
  needed.	
  With	
  NSURLSession	
  you	
  can	
  have	
  a	
  hybrid	
  
approach,	
  use	
  the	
  asynchronous	
  block	
  based	
  methods	
  and	
  also	
  setup	
  a	
  delegate	
  to	
  
handle	
  authen2ca2on.	
  
	
  -­‐	
  Uploads	
  and	
  downloads	
  through	
  the	
  file	
  system:	
  This	
  encourages	
  the	
  separa2on	
  of	
  the	
  
data	
  (file	
  contents)	
  from	
  the	
  metadata	
  (the	
  URL	
  and	
  se]ngs).	
  
Let’s	
  compare!	
  
NSURLConnec-on	
  

NSURLSession

AFNetworking
A simple request to API/Server using
completion blocks.
Web	
  Caching	
  
A	
  web	
  cache	
  is	
  a	
  mechanism	
  for	
  the	
  temporary	
  storage	
  (caching)	
  of	
  web	
  documents,	
  
such	
  as	
  HTML	
  pages	
  and	
  images,	
  to	
  reduce	
  bandwidth	
  usage,	
  server	
  load,	
  and	
  
perceived	
  lag.	
  A	
  web	
  cache	
  stores	
  copies	
  of	
  documents	
  passing	
  through	
  it.	
  
A	
  client,	
  such	
  as	
  a	
  web	
  browser,	
  can	
  store	
  web	
  content	
  for	
  reuse.	
  
For	
  example	
  :	
  if	
  the	
  back	
  buDon	
  is	
  pressed,	
  the	
  local	
  cached	
  version	
  of	
  a	
  page	
  may	
  be	
  
displayed	
  instead	
  of	
  a	
  new	
  request	
  being	
  sent	
  to	
  the	
  web	
  server.	
  
How	
  do	
  we	
  cache?	
  
NSURLCache	
  provides	
  a	
  composite	
  in-­‐memory	
  and	
  on-­‐disk	
  caching	
  mechanism	
  for	
  URL	
  requests	
  
to	
  your	
  applica2on.	
  As	
  part	
  of	
  Founda2on's	
  URL	
  Loading	
  System,	
  any	
  request	
  loaded	
  through	
  
NSURLConnec2on	
  will	
  be	
  handled	
  by	
  NSURLCache.	
  
Network	
  caching	
  reduces	
  the	
  number	
  of	
  requests	
  that	
  need	
  to	
  be	
  made	
  to	
  the	
  server,	
  and	
  
improve	
  the	
  experience	
  of	
  using	
  an	
  applica2on	
  offline	
  or	
  under	
  slow	
  network	
  condi2ons.	
  
When	
  a	
  request	
  has	
  finished	
  loading	
  its	
  response	
  from	
  the	
  server,	
  a	
  cached	
  response	
  will	
  be	
  
saved	
  locally.	
  The	
  next	
  2me	
  the	
  same	
  request	
  is	
  made,	
  the	
  locally-­‐cached	
  response	
  will	
  be	
  
returned	
  immediately,	
  without	
  connec2ng	
  to	
  the	
  server.	
  NSURLCache	
  returns	
  the	
  cached	
  
response	
  automa&cally	
  and	
  transparently.	
  
NSURLRequestCachePolicy	
  
Caching	
  policies	
  are	
  specified	
  in	
  both	
  the	
  request	
  (by	
  the	
  client)	
  and	
  in	
  the	
  response	
  (by	
  the	
  server).	
  
NSURLRequest	
  has	
  a	
  cachePolicy	
  property,	
  which	
  specifies	
  the	
  caching	
  behavior	
  of	
  the	
  request	
  
according	
  to	
  the	
  following	
  constants:	
  
NSURLRequestUseProtocolCachePolicy	
  	
  =	
  default	
  behavior.	
  
NSURLRequestReloadIgnoringLocalCacheData	
  =	
  don’t	
  use	
  the	
  cache.	
  
NSURLRequestReloadIgnoringLocalAndRemoteCacheData	
  =	
  seriously	
  don’t	
  use	
  the	
  cache.	
  
NSURLRequestReturnCacheDataElseLoad	
  =	
  Use	
  the	
  cache	
  no	
  ma9er	
  how	
  out	
  of	
  date,	
  or	
  if	
  no	
  cached	
  response	
  exists,	
  load	
  from	
  
the	
  network.	
  
NSURLRequestReturnCacheDataDontLoad	
  =	
  Offline	
  mode.	
  Always	
  use	
  the	
  cache	
  no	
  ma9er	
  how	
  out	
  of	
  date.	
  
NSURLRequestReloadRevalida-ngCacheData	
  =	
  Validate	
  cache	
  against	
  server	
  before	
  using.	
  
Conclusion	
  

NSURLSession

NSURLSession can do every
NSURLConnection can do and
AFNetworking can do every
NSURLConnection and NSURLSession
can do. But you can also do
AFNetworking can do using
NSURLConnection and NSURLSession
just a little bunch of codes.

AFNetworking

All of them are capable of using Cache
policy in communication of server CacheControl header.

NSURLConnect

AFNetworking has a great category
method in UIImageView that automatically
request the image and cache it while the
app is running.

More Related Content

What's hot

Enable oracle database vault
Enable oracle database vaultEnable oracle database vault
Enable oracle database vaultOsama Mustafa
 
Cloud init and cloud provisioning [openstack summit vancouver]
Cloud init and cloud provisioning [openstack summit vancouver]Cloud init and cloud provisioning [openstack summit vancouver]
Cloud init and cloud provisioning [openstack summit vancouver]Joshua Harlow
 
How to run appache spark on windows(in sbt console)
How to run appache spark on windows(in sbt console)How to run appache spark on windows(in sbt console)
How to run appache spark on windows(in sbt console)Ankit Kaneri
 
Eouc 12 on 12c osama mustafa
Eouc 12 on 12c osama mustafaEouc 12 on 12c osama mustafa
Eouc 12 on 12c osama mustafaOsama Mustafa
 
Learning Oracle with Oracle VM VirtualBox
Learning Oracle with Oracle VM VirtualBoxLearning Oracle with Oracle VM VirtualBox
Learning Oracle with Oracle VM VirtualBoxLeighton Nelson
 
Java troubleshooting thread dump
Java troubleshooting thread dumpJava troubleshooting thread dump
Java troubleshooting thread dumpejlp12
 
Network Automation: Ansible 101
Network Automation: Ansible 101Network Automation: Ansible 101
Network Automation: Ansible 101APNIC
 
Installation & configuration of IBM Cloud Orchestrator v2.5
Installation & configuration of IBM Cloud Orchestrator v2.5Installation & configuration of IBM Cloud Orchestrator v2.5
Installation & configuration of IBM Cloud Orchestrator v2.5Paulraj Pappaiah
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentationSuresh Kumar
 
Apache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling OutApache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling OutSander Temme
 
Threading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondThreading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondMind The Firebird
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptwebhostingguy
 
Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2ShepHertz
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The SnailMarcus Deglos
 
Ejabberd installation configuration
Ejabberd installation configurationEjabberd installation configuration
Ejabberd installation configurationShaojie Yang
 
VMUGIT UC 2013 - 06 Mike Laverick
VMUGIT UC 2013 - 06 Mike LaverickVMUGIT UC 2013 - 06 Mike Laverick
VMUGIT UC 2013 - 06 Mike LaverickVMUG IT
 
Oracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLinkOracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLinkOsama Mustafa
 
Writing & Sharing Great Modules - Puppet Camp Boston
Writing & Sharing Great Modules - Puppet Camp BostonWriting & Sharing Great Modules - Puppet Camp Boston
Writing & Sharing Great Modules - Puppet Camp BostonPuppet
 

What's hot (20)

Enable oracle database vault
Enable oracle database vaultEnable oracle database vault
Enable oracle database vault
 
Cloud init and cloud provisioning [openstack summit vancouver]
Cloud init and cloud provisioning [openstack summit vancouver]Cloud init and cloud provisioning [openstack summit vancouver]
Cloud init and cloud provisioning [openstack summit vancouver]
 
How to run appache spark on windows(in sbt console)
How to run appache spark on windows(in sbt console)How to run appache spark on windows(in sbt console)
How to run appache spark on windows(in sbt console)
 
Eouc 12 on 12c osama mustafa
Eouc 12 on 12c osama mustafaEouc 12 on 12c osama mustafa
Eouc 12 on 12c osama mustafa
 
Learning Oracle with Oracle VM VirtualBox
Learning Oracle with Oracle VM VirtualBoxLearning Oracle with Oracle VM VirtualBox
Learning Oracle with Oracle VM VirtualBox
 
Java troubleshooting thread dump
Java troubleshooting thread dumpJava troubleshooting thread dump
Java troubleshooting thread dump
 
Network Automation: Ansible 101
Network Automation: Ansible 101Network Automation: Ansible 101
Network Automation: Ansible 101
 
Installation & configuration of IBM Cloud Orchestrator v2.5
Installation & configuration of IBM Cloud Orchestrator v2.5Installation & configuration of IBM Cloud Orchestrator v2.5
Installation & configuration of IBM Cloud Orchestrator v2.5
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Apache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling OutApache Performance Tuning: Scaling Out
Apache Performance Tuning: Scaling Out
 
Introduction to DSpace
Introduction to DSpaceIntroduction to DSpace
Introduction to DSpace
 
Threading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyondThreading through InterBase, Firebird, and beyond
Threading through InterBase, Firebird, and beyond
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.ppt
 
Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2Configuring MongoDB HA Replica Set on AWS EC2
Configuring MongoDB HA Replica Set on AWS EC2
 
Speeding Up The Snail
Speeding Up The SnailSpeeding Up The Snail
Speeding Up The Snail
 
Ejabberd installation configuration
Ejabberd installation configurationEjabberd installation configuration
Ejabberd installation configuration
 
VMUGIT UC 2013 - 06 Mike Laverick
VMUGIT UC 2013 - 06 Mike LaverickVMUGIT UC 2013 - 06 Mike Laverick
VMUGIT UC 2013 - 06 Mike Laverick
 
Hacking Tomcat
Hacking TomcatHacking Tomcat
Hacking Tomcat
 
Oracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLinkOracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLink
 
Writing & Sharing Great Modules - Puppet Camp Boston
Writing & Sharing Great Modules - Puppet Camp BostonWriting & Sharing Great Modules - Puppet Camp Boston
Writing & Sharing Great Modules - Puppet Camp Boston
 

Similar to AfNetworking vs. Native + Caching

How oracle 12c flexes its muscles against oracle 11g r2 final
How oracle 12c flexes its muscles against oracle 11g r2 finalHow oracle 12c flexes its muscles against oracle 11g r2 final
How oracle 12c flexes its muscles against oracle 11g r2 finalAjith Narayanan
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
Oracle Database 12c "New features"
Oracle Database 12c "New features" Oracle Database 12c "New features"
Oracle Database 12c "New features" Anar Godjaev
 
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...Vivek Adithya Mohankumar
 
Snowflake_Cheat_Sheet_Snowflake_Cheat_Sheet
Snowflake_Cheat_Sheet_Snowflake_Cheat_SheetSnowflake_Cheat_Sheet_Snowflake_Cheat_Sheet
Snowflake_Cheat_Sheet_Snowflake_Cheat_Sheetharipra2
 
JPJ1413 Towards Differential Query Services in Cost-Efficient Clouds
JPJ1413   Towards Differential Query Services in Cost-Efficient CloudsJPJ1413   Towards Differential Query Services in Cost-Efficient Clouds
JPJ1413 Towards Differential Query Services in Cost-Efficient Cloudschennaijp
 
Oracle RAC 12c Best Practices Sanger OOW13 [CON8805]
Oracle RAC 12c Best Practices Sanger OOW13 [CON8805]Oracle RAC 12c Best Practices Sanger OOW13 [CON8805]
Oracle RAC 12c Best Practices Sanger OOW13 [CON8805]Markus Michalewicz
 
Mastering OpenStack - Episode 06 - Controller Nodes
Mastering OpenStack - Episode 06 - Controller NodesMastering OpenStack - Episode 06 - Controller Nodes
Mastering OpenStack - Episode 06 - Controller NodesRoozbeh Shafiee
 
Testing Delphix: easy data virtualization
Testing Delphix: easy data virtualizationTesting Delphix: easy data virtualization
Testing Delphix: easy data virtualizationFranck Pachot
 
Altoros using no sql databases for interactive_applications
Altoros using no sql databases for interactive_applicationsAltoros using no sql databases for interactive_applications
Altoros using no sql databases for interactive_applicationsJeff Harris
 
Survey of open source cloud architectures
Survey of open source cloud architecturesSurvey of open source cloud architectures
Survey of open source cloud architecturesabhinav vedanbhatla
 
Hadoop Spark Introduction-20150130
Hadoop Spark Introduction-20150130Hadoop Spark Introduction-20150130
Hadoop Spark Introduction-20150130Xuan-Chao Huang
 
WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...
WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...
WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...WebCamp
 
twp-oracledatabasebackupservice-2183633
twp-oracledatabasebackupservice-2183633twp-oracledatabasebackupservice-2183633
twp-oracledatabasebackupservice-2183633Arush Jain
 

Similar to AfNetworking vs. Native + Caching (20)

How oracle 12c flexes its muscles against oracle 11g r2 final
How oracle 12c flexes its muscles against oracle 11g r2 finalHow oracle 12c flexes its muscles against oracle 11g r2 final
How oracle 12c flexes its muscles against oracle 11g r2 final
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Oracle Database 12c "New features"
Oracle Database 12c "New features" Oracle Database 12c "New features"
Oracle Database 12c "New features"
 
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
NoSQL Databases: An Introduction and Comparison between Dynamo, MongoDB and C...
 
Snowflake_Cheat_Sheet_Snowflake_Cheat_Sheet
Snowflake_Cheat_Sheet_Snowflake_Cheat_SheetSnowflake_Cheat_Sheet_Snowflake_Cheat_Sheet
Snowflake_Cheat_Sheet_Snowflake_Cheat_Sheet
 
JPJ1413 Towards Differential Query Services in Cost-Efficient Clouds
JPJ1413   Towards Differential Query Services in Cost-Efficient CloudsJPJ1413   Towards Differential Query Services in Cost-Efficient Clouds
JPJ1413 Towards Differential Query Services in Cost-Efficient Clouds
 
Oracle RAC 12c Best Practices Sanger OOW13 [CON8805]
Oracle RAC 12c Best Practices Sanger OOW13 [CON8805]Oracle RAC 12c Best Practices Sanger OOW13 [CON8805]
Oracle RAC 12c Best Practices Sanger OOW13 [CON8805]
 
Mastering OpenStack - Episode 06 - Controller Nodes
Mastering OpenStack - Episode 06 - Controller NodesMastering OpenStack - Episode 06 - Controller Nodes
Mastering OpenStack - Episode 06 - Controller Nodes
 
Testing Delphix: easy data virtualization
Testing Delphix: easy data virtualizationTesting Delphix: easy data virtualization
Testing Delphix: easy data virtualization
 
Altoros using no sql databases for interactive_applications
Altoros using no sql databases for interactive_applicationsAltoros using no sql databases for interactive_applications
Altoros using no sql databases for interactive_applications
 
draft_myungho
draft_myunghodraft_myungho
draft_myungho
 
ZDLRA in Action
ZDLRA in ActionZDLRA in Action
ZDLRA in Action
 
Survey of open source cloud architectures
Survey of open source cloud architecturesSurvey of open source cloud architectures
Survey of open source cloud architectures
 
Hadoop Spark Introduction-20150130
Hadoop Spark Introduction-20150130Hadoop Spark Introduction-20150130
Hadoop Spark Introduction-20150130
 
Concurrency and parallel in .net
Concurrency and parallel in .netConcurrency and parallel in .net
Concurrency and parallel in .net
 
WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...
WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...
WebCamp 2016: DevOps. Николай Дойков: Опыт создания клауда для потокового вид...
 
NetApp against ransomware
NetApp against ransomwareNetApp against ransomware
NetApp against ransomware
 
NodeJS @ ACS
NodeJS @ ACSNodeJS @ ACS
NodeJS @ ACS
 
twp-oracledatabasebackupservice-2183633
twp-oracledatabasebackupservice-2183633twp-oracledatabasebackupservice-2183633
twp-oracledatabasebackupservice-2183633
 
No sql
No sqlNo sql
No sql
 

More from KLabCyscorpions-TechBlog (13)

Object Calisthenics in Objective-C
Object Calisthenics in Objective-CObject Calisthenics in Objective-C
Object Calisthenics in Objective-C
 
Auto Layout on Xcode 5
Auto Layout on Xcode 5Auto Layout on Xcode 5
Auto Layout on Xcode 5
 
Code Review for iOS
Code Review for iOSCode Review for iOS
Code Review for iOS
 
Object Calisthenics
Object CalisthenicsObject Calisthenics
Object Calisthenics
 
Why You're A Bad PHP Programmer
Why You're A Bad PHP ProgrammerWhy You're A Bad PHP Programmer
Why You're A Bad PHP Programmer
 
Redis Set Go
Redis Set GoRedis Set Go
Redis Set Go
 
Redis Beyond
Redis BeyondRedis Beyond
Redis Beyond
 
X-Debug in Php Storm
X-Debug in Php StormX-Debug in Php Storm
X-Debug in Php Storm
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Php + MySql Optimization
Php + MySql OptimizationPhp + MySql Optimization
Php + MySql Optimization
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
MVC Web Application
MVC Web ApplicationMVC Web Application
MVC Web Application
 
Bash
BashBash
Bash
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

AfNetworking vs. Native + Caching

  • 1. AFNetworking  vs.  Na2ve   NSURLConnec2on  &     NSURLSession   +  Caching  
  • 2. What  is  AFNetworking?   AFNetworking  is  a  class  developed  by  MaD  Thompson  and  ScoD  Raymond  and  is   described  as  “a  delighHul  networking  library  for  iOS  and  Mac  OS  X.”  It  makes   common  tasks  like  asynchronous  hDp  requests  a  lot  easier.     AFNetworking  just  like  all  other  popular  libraries  to  do  the  same  all  use   NSURLConnec2on  to  do  the  actual  'work'.  They  just  include  a  bunch  of  friendly   methods  so  you  can  easily  make  requests  without  having  to  write  a  whole  lot  of   boilerplate  code  yourself.  
  • 3. Several  AFNetworking  benefits    -­‐  One  of  the  benefits  of  using  AFNetworking  is  the  data  type  classes  for  handling   response  data.  The  success  block  has  already  parsed  the  response  and  returns  the   data  for  you.  With  NSURLSession  you  receive  NSData  back  in  the  comple2on   handler,  so  you  would  need  to  convert  the  NSData  into  JSON  or  other  formats.    -­‐  It  also  helps  you  ensure  that  your  UI  is  responsive  even  when  your  app  is  in  the   middle  of  a  big  download.    -­‐  AFNetworking  adds  a  category  to  UIImageView  that  lets  you  load  images   asynchronously,  meaning  the  UI  will  remain  responsive  while  images  are   downloaded  in  the  background.  
  • 4. What  is  NSURLSession?   In  iOS  7,  Apple  has  introduced  NSURLSession,  which  is  a  suite  of  classes  that  replaces   NSURLConnec-on  as  the  preferred  method  of  networking.   Using  NSURLSession  is  just  as  easy  as  using  its  predecessor  NSURLConnec-on  for   simple  tasks.  
  • 5. Several  NSURLSession  new  advantages  and  benefits      -­‐  NSURLSession  is  created,  you  get  all  the  benefits  of  background  networking.  This  helps   with  baDery  life,  supports  UIKit  mul2tasking  and  uses  the  same  delegate  model  as  in-­‐ process  transfers.    -­‐  Ability  to  pause  and  resume  networking  opera-ons:  With  the  NSURLSession  API  any   networking  task  can  be  paused,  stopped,  and  restarted.  No  NSOpera2on  sub-­‐classing  is   necessary.    -­‐  Instead  of  storing  all  of  the  networking  objects  (such  as  a  response  cache)  globally,   NSURLSession  provides  a  mechanism  for  storing  objects  either  on  a  global  basis  or  on  a   per  session  basis.  
  • 6.    -­‐  Rich  delegate  model:  NSURLConnec-on  has  some  asynchronous  block  based  methods,   however  a  delegate  cannot  be  used  with  them.  When  the  request  is  made  it  either  works   or  fails,  even  if  authen2ca2on  was  needed.  With  NSURLSession  you  can  have  a  hybrid   approach,  use  the  asynchronous  block  based  methods  and  also  setup  a  delegate  to   handle  authen2ca2on.    -­‐  Uploads  and  downloads  through  the  file  system:  This  encourages  the  separa2on  of  the   data  (file  contents)  from  the  metadata  (the  URL  and  se]ngs).  
  • 7. Let’s  compare!   NSURLConnec-on   NSURLSession AFNetworking A simple request to API/Server using completion blocks.
  • 8. Web  Caching   A  web  cache  is  a  mechanism  for  the  temporary  storage  (caching)  of  web  documents,   such  as  HTML  pages  and  images,  to  reduce  bandwidth  usage,  server  load,  and   perceived  lag.  A  web  cache  stores  copies  of  documents  passing  through  it.   A  client,  such  as  a  web  browser,  can  store  web  content  for  reuse.   For  example  :  if  the  back  buDon  is  pressed,  the  local  cached  version  of  a  page  may  be   displayed  instead  of  a  new  request  being  sent  to  the  web  server.  
  • 9. How  do  we  cache?   NSURLCache  provides  a  composite  in-­‐memory  and  on-­‐disk  caching  mechanism  for  URL  requests   to  your  applica2on.  As  part  of  Founda2on's  URL  Loading  System,  any  request  loaded  through   NSURLConnec2on  will  be  handled  by  NSURLCache.   Network  caching  reduces  the  number  of  requests  that  need  to  be  made  to  the  server,  and   improve  the  experience  of  using  an  applica2on  offline  or  under  slow  network  condi2ons.   When  a  request  has  finished  loading  its  response  from  the  server,  a  cached  response  will  be   saved  locally.  The  next  2me  the  same  request  is  made,  the  locally-­‐cached  response  will  be   returned  immediately,  without  connec2ng  to  the  server.  NSURLCache  returns  the  cached   response  automa&cally  and  transparently.  
  • 10. NSURLRequestCachePolicy   Caching  policies  are  specified  in  both  the  request  (by  the  client)  and  in  the  response  (by  the  server).   NSURLRequest  has  a  cachePolicy  property,  which  specifies  the  caching  behavior  of  the  request   according  to  the  following  constants:   NSURLRequestUseProtocolCachePolicy    =  default  behavior.   NSURLRequestReloadIgnoringLocalCacheData  =  don’t  use  the  cache.   NSURLRequestReloadIgnoringLocalAndRemoteCacheData  =  seriously  don’t  use  the  cache.   NSURLRequestReturnCacheDataElseLoad  =  Use  the  cache  no  ma9er  how  out  of  date,  or  if  no  cached  response  exists,  load  from   the  network.   NSURLRequestReturnCacheDataDontLoad  =  Offline  mode.  Always  use  the  cache  no  ma9er  how  out  of  date.   NSURLRequestReloadRevalida-ngCacheData  =  Validate  cache  against  server  before  using.  
  • 11. Conclusion   NSURLSession NSURLSession can do every NSURLConnection can do and AFNetworking can do every NSURLConnection and NSURLSession can do. But you can also do AFNetworking can do using NSURLConnection and NSURLSession just a little bunch of codes. AFNetworking All of them are capable of using Cache policy in communication of server CacheControl header. NSURLConnect AFNetworking has a great category method in UIImageView that automatically request the image and cache it while the app is running.