Resource file for data initialization

Posted by Daniel Vela on March 21, 2011

To initialize a NSArray with sample data or configuration data, you can store a data file in the resources of the xcode project like shown in figure:

resource file xcode

To retrive data use the following code:

// Load the data of file: "Data.plist".  
NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"]; = [NSArray arrayWithContentsOfFile:dataPath];

* The array representation in the file identified by aPath must contain only property list objects (NSString, NSData, NSDate, NSNumber, NSArray, or NSDictionary objects)