Question

Hello everyone i have the following code :

  NSString* issuePath =[[self contentURL] URLByAppendingPathComponent:@"magazine"].path;

I have a file called a.plist in the above directory. I have to read the a.plist file contents. How to do that. Before the file was local and I was accessing it as follows

 NSString *path = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"plist"];
Was it helpful?

Solution

  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"a.plist"];       
NSMutableDictionary *plistContents = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

OTHER TIPS

Refer this file handler utility which provides API's to interact with most of your file related operations.

It exposed API for below features,

  • Check if the file, or directory, exists in the given path
  • Create a folder in a given path
  • Verify if a folder exists at a given path
  • Get the size of a file
  • Check if a file with that name exists in the folder
  • Check if this folder has more subfolder or if it's the last folder

File Handler Utility Class link

You can simply use the following method.

NSString *path = [[NSBundle mainBundle] pathForResource:@"a" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top