Reputation: 25
I have a project on desktop and a file in this folder so this file is in the same folder as my .m .h files.
I want to get the path of this file. The NSBundle
or NSHomeDerictory
didn't give me the correct path. It seems the paths they gave is related to the simulator, not my working space.
Upvotes: 1
Views: 5875
Reputation: 5312
What you want is to use [[NSBundle mainBundle] pathForResource:resource ofType:type];
to get the path of the file.
For example, if I were to instantiate an NSMutableArray from the contents of a plist file, I would do something like:
NSString *path = [[NSBundle mainBundle] pathForResource:@"savedArray" ofType:@"plist"];
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
You can do the same thing with resources of different types as well.
Upvotes: 4