Chapter 7. Data Storage and Retrieval

The topics covered in this chapter are as follows:

  • Loading the XML file data
  • Saving to the XML file data
  • Loading the JSON file data
  • Loading the PLIST file data
  • Saving the PLIST file data
  • Using NSUserDefaults

Introduction

In this chapter, we will take a look at how to save and retrieve data. It could be simple data, such as storing and comparing high scores, or it could be more complex data, such as level data. For levels, you can store details such as layout, enemy positions, and types, which will be imported when you load the data.

There are different ways in which data can be stored. They can be stored in XML, PLIST, and JSON file types. Each file type stores the same data in a different way. PLIST is more Mac- and iOS-specific, but XML and JSON are platform independent.

Apart from the preceding types, OS X and iOS also store data in NSUserDefaults, in which you don't have to worry about formatting your data type; you just need to pass in your value to be stored, and the data will be stored accordingly. This is the easiest way to save and retrieve data such as high scores and Boolean values.

Let's take a look at how to save and retrieve data using these different data files, starting with XML.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.135.249