Finding path to plist in Xcode project folder

2.6k views Asked by At

I have a plist in my Xcode project's resource folder but on physical drive it's in the top folder of my project. I want to read and write from this same file. Using NSBundle reads it properly and gives no problem. I'm using this code to read file path:

NSString *thePath = [[NSBundle mainBundle]  pathForResource:@"MyFile" ofType:@"plist"];

but i think NSBundle doesn't allow writing back and so it didn't work when i tried to write back the file. Using the following code creates/ updates file using application path

NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDirectory, YES);
NSString * docsDirectory = [pathArray objectAtIndex:0];
NSString *filePath = [docsDirectory stringByAppendingPathComponent:@"MyFile.plist"];

but for now, I need to write on internal file. Any solution to access it? Besides, I've tried giving path from my working directory to project directory. It also doesn't work.

1

There are 1 answers

5
Jim On

It's not NSBundle that doesn't support writing, it's iOS itself. iOS will not let your app write to its own bundle.