Home > 2010 Winter DPS913 > Introduction to iPhone OS “property list” (plist)

Introduction to iPhone OS “property list” (plist)

January 28, 2010 Leave a comment Go to comments

.

Simple data persistence can be done with a “property list”, also know as a plist. It is typically an XML-based storage format, for certain kinds of objects. Arrays or dictionaries can easily be stored in a plist.

This approach is good for simple data persistence, and low-volume/low-quantity data persistence.
.

Getting started with a plist

An array can be “round tripped”as a plist. Assuming that “myArray” is an array object, and the string “pathToFile” is a complete path and filename, here’s how you create/write a plist for the array:

    [myArray writeToFile:pathToFile atomically:YES];

Here’s how you open/read a plist into an array (again, assuming “pathToFile” is a string…):

    NSArray *myArray = [NSArray arrayWithContentsOfFile:pathToFile];

A dictionary can also be “round tripped” as a plist. Assume “myDict” is a dictionary object; and again, assuming “pathToFile”, here’s how you create/write a plist for the dictionary:

    [myDict writeToFile:pathToFile atomically:YES];

Here’s how you open/read a plist into a dictionary (again, assuming “pathToFile”…):

    NSDictionary *myDict = [NSDictionary dictionaryWithContentsOfFile:pathToFile];

.

Allowable types in a plist

The following types can be stored in a plist:

  • NSDictionary
  • NSArray
  • NSString
  • NSNumber
  • NSData
  • NSDate

Nesting of NSDictionary and NSArray objects is permitted. This enables you to easily persist a hierarchical data structure.

.


Advertisements
Categories: 2010 Winter DPS913
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: