Reading plist files

Posted: October 15, 2010 in Snippets

It was only recently that I read about this function,


Creates and returns a dictionary using the keys and values found in a file specified by a given path.

+ (id)dictionaryWithContentsOfFile:(NSString *)path



A full or relative pathname. The file identified by path must contain a string representation of a property list whose root object is a dictionary. The dictionary must contain only property list objects (instances of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary). For more details, see Property List Programming Guide.

Return Value

A new dictionary that contains the dictionary at path, or nil if there is a file error or if the contents of the file are an invalid representation of a dictionary.


  • Available in iPhone OS 2.0 and later.


Hence, iPhone SDK has direct support for reading in plist files into a dictionary or an array.


NSString *propertiesPath = [[NSBundle mainBundle] pathForResource:@”properties” ofType:@”plist”];

NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:propertiesPath];

properties.plist file:

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “”&gt;

<plist version=”1.0″>











That would result in a dictionary with two key-value pairs

“Array_item” =     (




Name = Basit;


  1. […] This cup of tea was served by: Basit Ali’s Blog […]

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s