How to access files in the interior of an iPhone application?

I need an iPhone application to access the files that the application creates (.plist, etc.). There is a hard-coded way:

NSString *appDir = [[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
                      objectAtIndex:0] 
                     stringByDeletingLastPathComponent]
                    stringByAppendingPathComponent:appFolder];

where appFolderis the name of the folder application, for example, "test.app". Once appDir is known, file access is easy.

Is there any other, not hard-coded way to access files from an application?

Thank Advance

+3
source share
2 answers
 NSString* pathToFile = 
    [[[NSBundle mainBundle] resourcePath] 
         stringByAppendingPathComponent:@"myFile.plist"];

// or, even better (handling localization):
NSString* pathToFile = [[NSBundle mainBundle] pathForResource:@"myFile"
                                                       ofType:@"plist"];
+4
source

Your application folder is the โ€œmain packageโ€. So you can use NSBundle methods like

NSString* path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];
+1
source

Source: https://habr.com/ru/post/1743469/


All Articles