Read a plist from your resources folder in Iphone Objective C

By | March 6, 2011

Plist or property list are usually used for storing data in iPhone.
They are normal XML files, you can open it in a texteditor to view it’s data.
This sample code shows how to read data from the plist.
Reading a plist will return an array.You can print out the array to view the results.


     NSString *path= [[NSBundle mainBundle] pathForResource:@"plistName" ofType:@"plist"];
     BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
     if(fileExists){
         NSMutableArray *arr = [[NSArray alloc]  initWithContentsOfFile: path];
         NSLog(@"Data from plist %@",arr);
     }else {
        NSLog(@"File Not Found");
        exit(1);  // if file not found exit the application.
    }

Please leave your valuable comments………

Leave a Reply

Your email address will not be published. Required fields are marked *