Chapter 14. Networking

 

This chapter covers

  • Connecting to web services
  • Requesting data from a web service
  • Downloading from a web service
  • Parsing JSON data
  • Using dependency managers

Without a doubt, web services can transform an everyday app into an extraordinary experience. By hooking into the vast and diverse number of services and information online, or using the processing power of virtual servers, connecting to third-party web services can turn your humble app into an app that astounds!

You may be interested in connecting to your own web service, too. Perhaps Apple’s iCloud and CloudKit services don’t meet your needs precisely; maybe you need a more sophisticated back-end solution; or perhaps you already have a web service built that you hope to use.

In this chapter, we’ll focus on using iOS networking capabilities to connect your app with online web services. Along the way, you’ll encounter additional concepts:

  • URL sessions and URL session tasks
  • JSON serialization and SwiftyJSON
  • CocoaPods and Carthage
  • Operation queues
  • App Transport Security

14.1. Using a web service

14.2. Setting up a books service

14.3. Communicating with the web service

14.4. Creating a URL Session

14.5. Setting up the URL request

14.6. Requesting data from a web service

14.7. Examining the data

14.8. Parsing JSON data with JSONSerialization

14.9. Parsing JSON data with JSONDecoder

14.10. Parsing JSON data with SwiftyJSON

14.11. Downloading data from a web service

14.12. Displaying the network activity indicator

14.13. Cancelling a task

14.14. Summary