Chapter    7

Consuming Web Content

This chapter covers how to use web content with Objective-C.

The recipes in this chapter will show you how to:

  • Download files with NSURL
  • Use web services with XML and JSON
  • Parse both XML and JSON data
  • Use NSURLConnection to asynchronously consume web content

7.1 Downloading a File

Problem

You want to download a file from the Internet.

Solution

Use NSURL to specify a URL for a file and then use NSData to download the contents of that file into your file system.

NOTE: URL stands for Uniform Resource Locator. A URL is a character string that specifies the location of an Internet resource. NSURL is a Foundation class that lets you use URLs in Objective-C.

How It Works

For this solution you must have a file ...

Get Objective-C Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.