O'Reilly logo

Core Data in Swift by Marcus S. Zarra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Solution

A network operation is a discrete action and should be coded as such. Therefore, we’ll use a subclass of NSOperation as the basis for the network operation.

Instead of using the block-based API provided by Apple, we’ll use the delegate functions of NSURLSession to listen to events during the network operation. By implementing the delegate methods, our NSOperation subclass will be integrated into every step of the network request and can make decisions through the operation.

The workflow is as follows:

  1. Build the request
  2. Start network operation
  3. Receive a response from the server
  4. Receive N blocks of data from the server
  5. Receive a completion delegate callback
  6. Process the data

The start() Function

In our NSOperation subclass, we’ll handle ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required