Storing Files

Discussion in 'iOS Programming' started by john903, Sep 9, 2008.

  1. john903 macrumors member

    Joined:
    Apr 11, 2008
    #1
    What directory should your program use to save files? Do you just find your installation path or is there some other path developers are supposed to use to store files?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Use NSSearchPathForDirectoriesInDomains() along with NSDocumentDirectory to get the Documents folder for your application.
     
  3. Sbrocket macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #3
    Code:
    NSString *basePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    
    That will give you the appropriate Documents/ directory path for your application. You should store any files you need saved between sessions (or otherwise) there.
     
  4. john903 thread starter macrumors member

    Joined:
    Apr 11, 2008
    #4
    Thanks! I'm able to get the path but it looks like the folder is given permissions that are not allowing me to save files to the folder using fopen. Am I doing something wrong or do I need to change the permissions on the folder?

    Also, the name of the application folder, such as like CE9E47A8-38DC-4DDD-A0AA-93E0666DB241 keeps changing every time the program loads. Is that what's supposed to happen?
     

Share This Page