Reputation: 608
I want to access data (xml, to be specific) in different filepaths, depending on some parameters. In short, theres a /Saves/ folder, which contains several other folders (/Save1/, /Save2/, /Save3/, etc). I want to be able to parse.
Lets assume the file I want to access is in the following path:
/../projectname/Saves/Save1/dialogue.xml
Within finder I created the folder substructure and then copied it into my XCode project. That means, these folders exist in the filestructure and not just in XCode. Afterwards I'm trying to do the following:
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:"@/Saves/Save1/dialogue.xml"];
NSData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:path];
However, that doesn't seem to work properly. Logging the path variable I get the following:
/Users/<username>/Library/Application Support/iPhone Simulator/5.1/Application/<appcode>/<appname>.app/Saves/Save1/dialogue.xml
Where's my mistake? Thanks in advance for any help.
Upvotes: 0
Views: 145
Reputation: 38249
try this:
//NSString *path = [[NSBundle mainBundle] pathForResource:@"dialogue" ofType:@"xml" inDirectory:@"Saves/Save1"];
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Saves/Save1/dialogue.xml"];
if([[NSFileManager defaultManager] fileExitsAtPath:path])
{
NSMutableData *xmlData = [[NSMutableData alloc] initWithContentsOfFile:path];
}
else
{
NSLog(@"File doesnot exits");
}
Upvotes: 0
Reputation: 1066
Please make sure you have added same folder in project target also. One you add the same structure under project target and compile then same folders will be created in your .app file. then you can access it the way you mentioned.
Upvotes: 1