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:
In our NSOperation subclass, we’ll handle ...