Question

I was reading about Plist just before and I saw this Bit of code:

       [super viewDidLoad];
       NSString *path = [[NSBundle mainBundle] pathForResource:@"projects" ofType:@"plist"];
       projects = [NSArray arrayWithContentsOfFile:path];
       }

Now I've been manually putting in the file path of my property list, I'm curious is this the correct way to universally find the file path?

if so could someone please explain how it works to me, thanks.

Was it helpful?

Solution

Yes, for getting the file from your Main resources bundle.

For getting the resource path from you application document directory you can try like

/**
 Returns the URL to the application's Documents directory.
 */
- (NSURL *)applicationDocumentsDirectory
{
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}

which could be use like

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"yourFile.ext"];

OTHER TIPS

Yes this is the right way and its self explanatory too..first step you find the path of plist file and by then you are populating an array with the contents of plist file. If you use mutable array instead of array you can also edit the plist file and save back

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top