philippe philippe - 2 months ago 10x
Objective-C Question

iOS temporary folder location

This question turned to a Q&A, because I found the answer while
preparing it. Nevermind, I think it is worth precising this:

My app has just been rejected by Apple because it was storing temporary or cache files in the documents directory. Right. Their rejection message says that "Temporary files used by your app should only be stored in the
/tmp directory
". I suppose it is that besides the Documents and Library in the Application's folder.

I am now trying to debug this issue in the iPhone Simulator, and when I use
, the value I get in the XCode debugger is
, and not
/Users/me/Library/Application Support/iPhone Simulator/5.1/Applications/8F71AB72-598C-427A-A116-36833D3209F7/tmp/

So : is
having a different behaviour using the iPhone Simulator, and, is it possible to track the application's temporary directory at debug time ?



  • Data which is explicitly accepted by the user as personal, and potentially backuped in his/her iCloud space, should be written in user's "Documents" directory

  • Data that belongs and extends your application (an extension user can download for instance,...), but which is NOT in the bundle, should be written in a subfolder of "Application Support/" directory, having the title of your appID. It can also be the "Cache" directory.

  • Data with short-life time can be stored in the tmp directory of your application. In this case, use of NSTemporaryDirectory() is possible to get the "tmp" directory. Check this link for additional help.

Check this official iOS developement Apple page in section "Determining Where to Store Your App-Specific Files" for explanations.

Below are 3 functions in Swift designed to return NSURLs to these directories and make your like simpler.


func GetDocumentsDirectory()->NSURL{
    //returns User's "Documents" directory
    //something like this on a real device : file:///private/var/mobile/Containers/Data/Application/APPID/Documents/
    //something like this on the simulator : file:///Users/MACUSERID/Library/Developer/CoreSimulator/Devices/SIMDEVICEID/data/Containers/Data/Application/APPUUID/Documents/
    let filemgr = NSFileManager.defaultManager()
    let docsDirURL = try! filemgr.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: true)
    return docsDirURL

func GetApplicationSupportDirectory()->NSURL{
    //returns Application's support directory
    //something like this on a real device : file:///private/var/mobile/Containers/Data/Application/APPID/Library/Application%20Support/YOURAPPBUNDLEID/
    //something like this on the simulator : file:///Users/MACUSERID/Library/Developer/CoreSimulator/Devices/SIMDEVICEID/data/Containers/Data/Application/APPUUID/Library/Application%20Support/YOURAPPBUNDLEID/
    let AllDirectories : [NSURL]
    var ApplicationSupportDirectory : NSURL=NSURL.init()
    var ApplicationDirectory : NSURL=NSURL.init()
    AllDirectories=NSFileManager.defaultManager().URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)
    if AllDirectories.count>=1{
    if !ApplicationSupportDirectory.isEqual(nil) {
    return ApplicationDirectory

func GetTemporaryDirectory()->NSURL{
    //returns Application's temporary directory
    //something like this on a real device : file:///private/var/mobile/Containers/Data/Application/APPID/tmp/
    //something like this on the simulator : file:///Users/MACUSERID/Library/Developer/CoreSimulator/Devices/SIMDEVICEID/data/Containers/Data/Application/APPUUID/tmp/
    return NSURL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)