Tuesday, September 21, 2010

Reading a plist into an NSArray

Instead of hard coding elements into an array with string literals, such as in the following example:

NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:@"Eenie", @"Meanie", @"Minee", @"Moe", nil];

it is better (and always a good practice) to populate the elements for the array with values read in from a configuration file. In the case of populating values in an object (such as string values in a UIPickerView object when developing apps for the iPhone/iPod Touch), you can read in values from a property list (or .plist).

Rather than reinventing the wheel, I will point you to an existing quick and easy tutorial on how to read a plist into an NSArray, which I found over at iphonedevelopertips.com. I found it very useful myself:

Link to "Reading a plist into an NSArray"

No comments:

Post a Comment