Overview of iOS Application Directories

iOS applications have a limited number of directories available for writing content, the design intent is to ensure application security. This post will give a quick run down of the folder locations available in an iOS application and their intended use.

Documents Directory – ApplicationHome/Documents

The Documents directory is the primary location to save user and application related content. This directory and its subdirectories, are backed up when a user does a sync with iTunes. This is directory is also the repository for iTunes file sharing content.

The code below shows how to check for and print the path to the Document directory:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 
if ([paths count] > 0)
  NSLog(@"Documents directory: %@", [paths objectAtIndex:0] );

Documents Inbox – ApplicationHome/Documents/Inbox

The Documents Inbox is primarily used when an application such as the Mail app calls your app with a request to open a specific file type.

For example, in the post Register File Types to Associate File Extension with an App I wrote an example to demonstrate how to open a file attachment in an application. The file passed to the application (from the Mail Inbox) is stored in the Documents Inbox directory.

The content in the Documents Inbox directory is backed up when a device is synced with iTunes.

tmp – ApplicationHome/tmp

As the name implies, the tmp directory is available for files that are used only while your application running. A good practice would be to remove any files that you create here (before exiting your app). iOS may also clean this directory, however, this is not guaranteed.

The content in the tmp directory is not backed up when a device is synced with iTunes.

Library – ApplicationHome/Library

The Library directory is for intended for content that is not user generated. For example, if you have data that is read into your application at app startup, this would be a good place to store such information.

The content in the Library directory is backed up when a device is synced with iTunes, with one exception, there is a Caches directory that is not backed up.

  1. At the end of the Documents Inbox section, you have a little copy&paste typo:

    The content in the ***Library*** directory is backed up when a device is synced with iTunes.

  2. So what’s the difference really for the Documents folder and the Library folder? User settings would go in the Documents folder, but a cache would go in the Library folder?

    • I think of the Documents directory as primarily user centric (user preferences, saved content, etc). The Library folder could be used for content that is more specific to the app itself, maybe content stored in an XML or other file that provides app related information.

  3. Hi John,
    I’m no developer but interested in some background knowledge.
    You say
    “The content in the Documents Inbox directory is backed up when a device is synced with iTunes.”
    Is it right that this does not apply to e.g. documents folder of iWork apps like Numbers or Keynote when iCloud syncing is turned on.
    I turned it on and what I see in the File Sharing section of iTunes are old documents of the iWork suite.
    Thanks in advance.

    • Hello, seems iWork docs should be backed up…I would recommend checking on Apple site for more info.

Comments are closed.