Most iOS apps require at least some kind of network connectivity for data transfer, which means network programming is an important area to master as an iOS developer.
How to get on the path toward mastery?
I’ve found that the best approach to a learning topic in iOS — or programming in general — is to look at the topic from several different angles.
So in the spirit of viewing things with a wide perspective (rather than merely searching for “best practices”) I present to you 10 steps that can help you kick ass at iOS network programming:
Watch the WWDC videos Network Apps for iPhone OS Part 1 and Part 2 where Quinn “The Eskimo” discusses best practices for building iOS network apps. Even though this talk is from 2010, it is still very relevant. Especially the segments about designing your UI properly for handling network failures, using asynchronous network requests, and run loops. (Note: for some reason Apple’s streaming version is not working, so you may have to click “Resources” and then download the video. It’s worth it!)
Read Designing for Real World Networks to get an idea of how networks can be unpredictable and how Apple suggests you prepare for this. Most importantly, make the Network Link Conditioner tool your friend.
Read Adding an API-Backed UIPageViewController in Swift by Christina Moulton to learn from a full working example of how UI code interacts with a backend API.
Download and learn how to use Charles Proxy or another proxy software so that you can debug network apps. These proxy tools allow you to see the network requests that your app is making at any given time while it runs.
Read NSURLSession : Getting Started go through a tutorial that uses Apple’s official networking API.
Read Ash Furrow’s MVVM in Swift to learn an alternative way of architecting your app from conventional MVC, and how calling the network fits into this architecture.
Watch Chris Eidhof’s talk on Tiny networking in Swift to see how you can leverage features in Swift to make networking in iOS simpler but also more powerful, without relying on a heavyweight networking library.
Read Introduction to the Sockets API by Mike Ash to get a deeper look at sockets in iOS and how the low-level sockets API works under the hood.
Check out my own article on how to quickly get a Python backend API and connect it with your Swift code — The Backwards Backend Technique.