Where is the Documents Directory for the iOS 8 Simulator

xcode-6-iconYou may have noticed that the iPhone Simulator has changed with Xcode 6, and with it – of course – the path to your simulated apps’ Documents Directory. At times we may need to take a look at it.

Finding that path is not as easy as it was once, namely Library/Application Support/iPhone Simulator/7.1/Applications/ followed by a cryptic number representing your app.

As of Xcode 6 and iOS 8 you’ll find it here:
Library/Developer/CoreSimulator/Devices/cryptic number/data/Containers/Data/Application/cryptic number

It was fairly easy to spot that one cryptic number before – but now you have to play the guessing game twice. This can become tedious, especially if you’re testing several user accounts and therefore accumulate a vast array of cryptic numbers.

Here’s a great way of writing out the Documents directory as a log message:

Add this to a viewDidLoad or applicationDidFinishLaunching method and you’re golden. If you’re running the app on a Simulator, this will write out the correct location for the current app.

Thanks to Ian for this tip!

Worse yet: every time you run the app, the folder location changes!

Thanks to Keith for bringing this up:

The location of this folder changes every time you run the app on the Simulator. Only Apple know why.

The good news is that once you open a Finder window and navigate to your project, Finder will update the location automatically as long as you don’t close that window.

At least this way you don’t have to play detective every time you launch the app from Xcode.

Complex and Cumbersome Method

Originally I did the following to detect where they Documents directory was:

  • add an identifiable file to your bundle (for example, a picture)
  • copy that file into your app’s Documents directory, using a name you can remember
  • run the app on the simulator
  • search for the file on the command line

Here’s how I did this:

This will copy a hypothetical file “swift-icon.png” from the Main Bundle to the simulator’s Documents directory as “WhereAreYouHiding-4s”. I’m adding 4s here because I’d like to find that particular simulator’s directory – which is likely different for the other models.

Searching for this file in Finder won’t yield any results – because a standard user does not have the permissions to read the simulator’s directory. Hence we’ll open Terminal and look for our file with root privileges:

This will prompt you to type in your Administrator password for your Mac and will go to work. The find command will look through every file on your hard disk and should only come up with very few results. Once you’ve found something resembling that cryptic path I’ve mentioned above, you can stop the search with CTRL+C.

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

30 thoughts on “Where is the Documents Directory for the iOS 8 Simulator

  1. Why not do sudo find /Library/Developer/CoreSimulator/Devices -name ‘WhereAreYou*’ to narrow the scope to where you actually want to search?

    1. That’s a good way of speeding up the search process – now that we know in which folder those files are hiding. Thanks for the tip, Nick!

    2. I’m working on a cordova based ios application and in my application, I am storing the application related configuration files under library directory. The very first time when the application is installed on iphone these files will get created and are used futher. I was able to create files under the library directory in IOS7. But in IOS 8 Beta5, Xcode6 beta5, and cordova 3.5 when I try to create the files/Subdirectories under Library Directory I get ABORT_ERR.

      Kindly advice.

  2. Hey Jay! Another great way to easily get the location that typically stays true no matter where the folder moves to is to log the main bundle’s location to console at startup.

    NSLog(@”Simulator build running from: %@”, [ [NSBundle mainBundle] bundleURL] );

    1. whoops, rather the Documents folder, or wherever else you’re looking

      NSLogVerbose(@”Document folder: %@”, [ [NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] );

  3. Strangely, it seems to change the location where it is running in the simulator each time you run the app! In other words, it runs in a different directory each time. In previous versions of Xcode it would run in the same location until you did a clean. Yet, Xcode/Simulator is persisting the changes made to local files somewhere and then copying them to the new target directory with each run of the app. My question: where is this data persisted? I do some testing and development work on these files between runs and need to know where they are “coming from”. Vexing.

    1. The plot thickens! I hadn’t noticed this, thanks for the heads-up, Keith. Is this happening in the same Xcode beta, or could this be related to beta version increments (i.e. it’s different in beta 3 than in beta 4)?

  4. This is happening even in Beta 5. The worst part in my case is that I need a Db file that has cached data and I am never able to get it on a subsequent run. In my case, it is not even persisted else where.

    1. Confirmed, Deepak. I have to say, of all the betas I’ve seen over the years, Xcode 6 and iOS 8 are the worst. I doubt that it’s a bug though, I bet it’s a “feature”. You’d think that there’s a built-in menu item in Xcode that would take us straight to the Documents folder. They even expose what’s happening in iCloud, why not expose this for us too?

      This has to be one of the worst design decisions ever. Apple clearly don’t want us to explore the file system directly anymore.

  5. Quick Update

    I’ve noticed that if you open a Finder window and navigate to your project, Finder will update the location of the Documents folder automatically – as long as you don’t close that window. At least this way you don’t have to play detective every time you launch the app from Xcode.

    I’ve added this tidbit and all your great suggestions to the top of the article. Thanks for all your input by the way!

  6. Found that if you look inside the hidden .plist file at Library/Developer/CoreSimulator/Devices/.default_created.plist it gives the current mapped location for all simulators.

  7. Thanks @Ferran,

    The symlinking script is a a good idea. I am searching for an easier way for users of “https://github.com/yepher/CoreDataUtility” to find their core data files in the Simulator. Your script gives me a good start.

  8. Here is another way to get the UUID for a given simulator:

    > xcrun simctl list

    It will output something like this:

    == Device Types ==
    iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
    iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
    iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)
    iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus)
    iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)
    iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2)
    iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina)
    iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air)
    Resizable iPhone (com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone)
    Resizable iPad (com.apple.CoreSimulator.SimDeviceType.Resizable-iPad)
    == Runtimes ==
    iOS 7.0 (7.0 – Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-7-0) (unavailable, runtime path not found)
    iOS 7.1 (7.1 – Unknown) (com.apple.CoreSimulator.SimRuntime.iOS-7-1) (unavailable, runtime path not found)
    iOS 8.0 (8.0 – 12A365) (com.apple.CoreSimulator.SimRuntime.iOS-8-0)
    == Devices ==
    — iOS 7.0 —
    — iOS 7.1 —
    — iOS 8.0 —
    iPhone 4s (CC5966F7-BA51-4A47-98C4-50B06B0DC05C) (Shutdown)
    iPhone 5 (73826557-CA90-4370-B279-BD45140B8CB6) (Shutdown)
    iPhone 5s (B5F37CBC-D69D-43C1-AEC9-62A709652265) (Shutdown)
    iPhone 6 Plus (C7FA676B-F325-4D4B-8066-5D9D8D752E68) (Shutdown)
    iPhone 6 (E75EFE2B-6D7E-4FB8-8554-A9A2CAA5027A) (Shutdown)
    iPad 2 (6392DF1E-C446-485D-BD0C-1E332BCAABF8) (Shutdown)
    iPad Retina (3707C304-2FB3-47C6-B8A6-B8726ACD78A6) (Shutdown)
    iPad Air (6D255EFC-F363-45C3-9F52-7E17634B57AF) (Shutdown)
    Resizable iPhone (B4D678FA-1E33-4705-BB3F-0CDCC0A5FC3F) (Shutdown)
    Resizable iPad (F650FB35-F2B4-445B-BE29-C5F2F6BF76C4) (Shutdown)

  9. Even better…

    As has been suggested, do some variation on this theme:

    NSLog(@”Document folder: %@”, [ [NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] );

    The cool trick… simple select this output in your console, right click and select: Services->Reveal In Finder.

    Services don’t get nearly enough respect.

    1. I’m trying to duplicate this in Swift with little success thus far. Anyone else unraveled this mystery? Thanks!

  10. If you use symlinks in your app, they will break every time you run your app on the simulator because the directory is moved, but symlinks point to the old directory.

  11. I ended up using this in Ruby to get the latest sim build:

    Dir.glob(File.join(ENV[‘HOME’],’/Library/Developer/CoreSimulator/Devices/*/Data/Containers/Bundle/Application/*/Foo.app’)).sort_by{ |f| File.ctime(f) }.reverse[0]

    Where Foo.app is replaced with the name of the app you are using

  12. I have problems even running the app in the device. I use two configuration files that the app needs to read. The first time it reads the files, all is well, but the second time the app doesn’t find them. I checked and it is trying to find them in the same folder. With Xcode 6 the files disappeared in iTunes after the first run. In Xcode 5 they’re still there, but the app doesn’t see them. I’ve been using the same logic for a couple of years, and suddenly it doesn’t work any more. Not the first thing that such a thing happened to me trying to develop for iOs, though.

  13. What about writing a file into the documents directory with the name like bundle identifier (on app start)? Just find the file by bundle identifier.

    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    NSURL *filepath = [[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] URLByAppendingPathComponent:[[NSBundle mainBundle] bundleIdentifier]];
    [[[NSBundle mainBundle] bundleIdentifier] writeToURL:filepath atomically:YES encoding:NSUTF8StringEncoding error:nil];
    return YES;

    In the console:

    dirname $(find /Users/nicolai/Library/Developer/CoreSimulator/Devices/ -iname ‘foo.bar.identifier’ | grep ‘Documents’)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.