Book Image

iOS and OS X Network Programming Cookbook

By : Jon Hoffman
Book Image

iOS and OS X Network Programming Cookbook

By: Jon Hoffman

Overview of this book

Table of Contents (15 chapters)
iOS and OS X Network Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating and using the MKNetworkKit engine


In this recipe we will be creating a subclass of MKNetworkEngine; this creates an iTunes engine to perform a search using the iTunes Web API. While it is not necessary to create a subclass of MKNetworkEngine for each host that you are connecting to, it is recommended.

There are three main advantages to subclassing MKNetworkEngine. They are as follows:

  • Each subclass of MKNetworkEngine contains its own Reachability object. This Reachability object will notify our class if there are changes in its availability or how we connect to the server.

  • Each subclass also contains its own set of queues for MKNetworkOperation.

  • You can customize an engine to the needs of a specific server.

For best practice, we want to set up a separate MKNetworkEngine subclass for each host that we connect to. As an example, if our application was connecting to Yahoo and iTunes, we would want to have two MKNetworkEngine subclasses; one for Yahoo and one for iTunes. We can set up our...