I need in a iPhone app to access files that the app is build with(.plist etc). There's an hardcoded way to do this:
NSString *appDir = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
objectAtIndex:0]
stringByDeletingLastPathComponent]
stringByAppendingPathComponent:appFolder];
where appFolder
is the name o开发者_StackOverflow中文版f folder app, like "test.app". After the appDir is known, to access files is simple.
Is there any other, not-hardcoded way to have access to files form the app?
Thanks in Advance!
NSString* pathToFile =
[[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"myFile.plist"];
// or, even better (handling localization):
NSString* pathToFile = [[NSBundle mainBundle] pathForResource:@"myFile"
ofType:@"plist"];
Your app folder is the "main bundle". So you can use NSBundle methods such as
NSString* path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];
精彩评论