14 Mar 2011

Using Property Lists

Mobile, Objective C No Comments

A simple way to get values or settings into a project without having to mess around too much! Just create a property list in xcode called Settings.plist for example and add any key values you need. Then when you instantiate your model load it in as an NSDictionary in and voila!

//Load in Settings
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *plistPath = [path stringByAppendingPathComponent:@"Settings.plist"];
NSDictionary *plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:plistPath] retain];

//Now get out a value using the key name that we have entered in our pList in xcode
NSString *jsonStringURL =  [plistDictionary objectForKey:@"JSON_URL"];

//Show an alert with the value
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"pList Settings" message: jsonStringURL delegate: self cancelButtonTitle: @"OK" otherButtonTitles: nil];
[alert show];
[alert release];

No Responses to “Using Property Lists”

Leave a Reply