Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the path of resource folder?

Tags:

iphone

Is there any way (programmatically) that i can find the location of "Resource" folder. I want to create a new file in it at run time.

like image 266
Abhinav Avatar asked Feb 26 '23 11:02

Abhinav


1 Answers

To get path to resource folder use:

NSString *path = [[NSBundle mainBundle] resourcePath];

However you won't be able to write anything there in run-time. New files should be saved to 1 of the following directories (depending of their usage):

  1. Documents directory - persists between app launches and backuped by iTunes

    NSString* docPath = [NSSearchPathForDirectoriesInDomains
                   (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
  2. Caches directory - persists between app launches but not backuped by iTunes - you should place there files that can be easily restored by your program to improve device backup time

    NSString* cachesPath = [NSSearchPathForDirectoriesInDomains
                   (NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
  3. Temporary directory - may not persist between app launches

    NSString* tempPath = NSTemporaryDirectory();
    
like image 89
Vladimir Avatar answered Mar 08 '23 03:03

Vladimir