IOS:Directories
lastmod 2014-03-24created 2014-03-242 edits
An iOS app has several directories for writing and reading data. These directories are sandboxed and can be accessed only by that app.
Documents directory
The Documents directory is for writing user data, mainly where content the app uses at the user's direction is stored. The meaning is a bit awkward, but it means that, except for temporary files, you can store and read most data in this directory.
Of course, it can have subdirectories.
This directory is also backed up by iTunes, and it is also where files are put into the app through iTunes.
To get the Documents directory path, use the following code:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([paths count] > 0) {
NSLog(@"Documents directory: %@", [paths objectAtIndex:0] );
}
Unless it is a special case, the paths obtained above will contain only one item.
For reference, there was talk not long ago that Apple restricts excessive use of this directory.
Temporary directory
For storing temporary files the app uses while running. However, files cached directly by the iOS SDK are not stored here.
Since they are temporary files, it is best for the app to delete the files it wrote itself whenever possible. iOS may also clear the contents of tmp on its own, but there is no telling when.
The temporary directory path can be obtained as follows.