Russell Broadbent

Yorkshire based web developer

iOS 4 – Loading custom plist data

To load data from a plist file first declare an array in your header file


@interface MyTableViewController : UITableViewController
	NSMutableArray *dataArray;


Then in the implementation file under the viewDidLoad method

@synthesize dataArray;

- (void)viewDidLoad
	// load our data from a plist file inside our app bundle
	NSString *path = [[NSBundle mainBundle] pathForResource:@"tableData" ofType:@"plist"];
	self.dataArray = [NSMutableArray arrayWithContentsOfFile:path];

providing your data file is called tableData.plist and not forgetting to synthesize the array

When the view unloads be sure to set this array to nil as it may be rather large

- (void)viewDidUnload
	self.dataArray = nil;

Comments are closed.