Xcode 6 iPhone Simulator Application Support location
Asked Answered
G

16

137

In Xcode 6, I have an app I'm using Core Data in, but there is no folder in Application Support for the iOS 8 iPhone Simulator. Where are my files and Core Data sqlite database being stored?

Granduncle answered 18/6, 2014 at 16:45 Comment(4)
Try this. There is an app which directly opens the Documents directory of the latest app run.Excruciate
I added an answer (at the bottom of the other answers) that shows how to programmatically get the path where the Core Data files reside.Wednesday
Have a look to this link..#24133522Periphery
Use "NSTemporaryDirectory ()". Look this- #1108576Kraska
C
298

The simulator directory has been moved with Xcode 6 beta to...

~/Library/Developer/CoreSimulator

Browsing the directory to your app's Documents folder is a bit more arduous, e.g.,

~/Library/Developer/CoreSimulator/Devices/4D2D127A-7103-41B2-872B-2DB891B978A2/data/Containers/Data/Application/0323215C-2B91-47F7-BE81-EB24B4DA7339/Documents/MyApp.sqlite
Contradict answered 18/6, 2014 at 16:50 Comment(10)
this is correct in general but it seems there are more internal folder changes. This is the path that works for me in Xcode Beta 3: ~/Library/Developer/CoreSimulator/Devices/B2C6629C-998D-4E84-9ADB-06CAF5BA4B89/data/Containers/Data/Application/62593001-FADA-4647-AA80-FE9973956C05/Documents/Mockingbird
Is there a way to understand that numbers or brute force is the only chance to get to data?Skip
NSLog(@"app dir: %@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]); - will print the full path to data folderSkip
I needed a persistent shortcut to my app's documents directory, for quick debugging. After application didFinishLaunchingWithOptions. #if DEBUG NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]; NSString *aliasPath = [NSString stringWithFormat:@"XCodePaths/%@", appName]; remove([aliasPath UTF8String]); [[NSFileManager defaultManager]createSymbolicLinkAtPath:aliasPath withDestinationPath:DOCS_DIR error:nil]; #endif Now I've got a simlink that works, even though iOS8 + XCode6 changes my App's Data GUID everytime I build.Avuncular
The xcrun simctl list command can be used to see the correspondence between the simulator names and the device UDIDs. Or more specifically the xcrun simctl list devices command.Jannet
Something weird happens. I save the files to the data directory and print the directory path to see where they are, I go to finder to look for it and that application folder doesn't exist. It seems that the names are constantly changing.Hinz
In the debugger, you can type ` po [[[NSFileManager defaultManager] URLsForDirectory: 9 inDomains: 1] lastObject]` (as it doesn't know what NSDocumentDirectory or NSUSerDomainMask are).Autopilot
@Scott Gardner can you update your answer please? The directory names change consistently. vir us has a much more appropriate solution.Trangtranquada
Use "NSTemporaryDirectory ()". Look this- #1108576Kraska
@Jannet There's also a file default_created.plist in ~/Library/Developer/CoreSimulator/Devices that lists all the simulators and their UDID.Kirchhoff
K
36

I would suggest that you use SimPholders to find your Simulator files. It is a menu bar item that tracks your simulator apps and lets you go directly to their folders and content. It's awesome.

Knockabout answered 24/10, 2014 at 22:20 Comment(3)
I was also having issues with SimPholders2 on Yosemite, so I started a command line script to help you find and open a Finder window to the simulator and App you want. It goes through the folders and metadata plists to list all simulator folders and Apps. If interested, check it out hereChokedamp
SimPholders2 works in Yosemite but it's a bit slow; once you click the icon in the status bar, just wait a few seconds and it should appear.Horrify
Whoa it's awesome and latest works with Yosemite + Xcode 6.3!Palpitate
B
21

I found SimulatorManager application very useful. It takes you directly to the application folder of installed simulators. I have tried with 7.1, 8.0 and 8.1 simulators.

SimulatorManager resides as an icon in the system tray and provides an option to "Launch At Login".

enter image description here

Note: This works only with Xcode 6 (6.1.1 in my case) and above.

Hope that helps!

Brakeman answered 4/12, 2014 at 7:49 Comment(2)
Amar, how do you install the SimulatorManager? I thought it was a plugin to Xcode but it is an Xcode projectSelfloading
in the top bar select: Product -> Archive -> and then Export the Archive as a Mac Application without re-signing (the last option) you will get a .app file which you can put in your Application folder like a normal application...Lanthorn
S
11

To know where your .sqlite file is stored in your AppDelegate.m add the following code

- (NSURL *)applicationDocumentsDirectory
{
    NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory      inDomains:NSUserDomainMask] lastObject]);

    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory     inDomains:NSUserDomainMask] lastObject];
 }

now call this method in AppDelegate.m

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

  //call here
   [self applicationDocumentsDirectory];

}
Slipon answered 15/10, 2014 at 7:57 Comment(1)
great.. specially useful when there are multiple simulatorsFelicidadfelicie
C
6

This worked for me in swift:

let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
println("App Path: \(dirPaths)")
Cotta answered 8/2, 2015 at 21:43 Comment(0)
A
3

I wrestled with this for some time. It became a huge pain to simply get to my local sqlite db. I wrote this script and made it a code snippet inside XCode. I place it inside my appDidFinishLaunching inside my appDelegate.


//xcode 6 moves the documents dir every time. haven't found out why yet. 

    #if DEBUG 

         NSLog(@"caching documents dir for xcode 6. %@", [NSBundle mainBundle]); 

         NSString *toFile = @"XCodePaths/lastBuild.txt"; NSError *err = nil; 

         [DOCS_DIR writeToFile:toFile atomically:YES encoding:NSUTF8StringEncoding error:&err]; 

         if(err) 
            NSLog(@"%@", [err localizedDescription]);

         NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];   

         NSString *aliasPath = [NSString stringWithFormat:@"XCodePaths/%@", appName]; 

         remove([aliasPath UTF8String]); 

         [[NSFileManager defaultManager] createSymbolicLinkAtPath:aliasPath withDestinationPath:DOCS_DIR error:nil]; 

     #endif

This creates a simlink at the root of your drive. (You might have to create this folder yourself the first time, and chmod it, or you can change the location to some other place) Then I installed the xcodeway plugin https://github.com/onmyway133/XcodeWay

I modified it a bit so that it will allow me to simply press cmd+d and it will open a finder winder to my current application's persistent Documents directory. This way, not matter how many times XCode changes your path, it only changes on run, and it updates your simlink immediately on each run.

I hope this is useful for others!

Avuncular answered 9/10, 2014 at 13:56 Comment(1)
Thanks, I just update XcodeWay to support iOS 8 simulator folderVelazquez
T
3

Open finder>Library>Developer>CoreSimulator>Devices

Then Change Arrangement icon from finder select Date Added

Select your app >data>Container>data>Applications>

choose your app >Documents>Here is your db file

In my case:

/Users/pluto/Library/Developer/CoreSimulator/Devices/A75107D2-A535-415A-865D-978B2555370B/data/Containers/Data/Application/265A12BC-FF5B-4235-B5EF-6022B83754B4/Documents/dboPhotoBucket.sqlite

Otherwise do this :

NSLog(@"app dir: %@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]); 

- It will print the full path to data folder.

Swift:

let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
println("App Path: \(dirPaths)")
Trudge answered 8/12, 2014 at 12:42 Comment(1)
Swift 3.0: let dirPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) print("App Path: \(dirPaths)")Stillhunt
C
2

Use Finder-->go to folder and enter given basepath to reach application folders

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

NSLog(@"%@",basePath);
Cahn answered 11/10, 2014 at 9:50 Comment(0)
P
1

The simulator puts the file in ~/Library/Developer/CoreSimulator/Devices/... but the path after /Devices is different for everyone.

Use this handy method. It returns the path of the temporary directory for the current user and takes no argument.

NSString * NSTemporaryDirectory ( void );

So in my ViewController class I usually put this line in my viewDidLoad just for a reference when I need to grab my CoreData stored file. Hope this helps.

  NSLog(@"FILE PATH :%@", NSTemporaryDirectory());

(Note: to go to the path, from the finder menu click on Go and type ~/Library to open hidden directory then in the Finder Window you can click on the path shown on your console.)

President answered 14/11, 2014 at 18:49 Comment(0)
R
1

This location has, once again, changed, if using Swift, use this to find out where the folder is (this is copied from the AppDelegate.swift file that Apple creates for you so if it doesn't work on your machine, search in that file for the right syntax, this works on mine using Xcode 6.1 and iOS 8 simulator):

let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
println("Possible sqlite file: \(urls)")
Rabelaisian answered 27/11, 2014 at 14:50 Comment(0)
E
1

The simulators are located under:

~/Library/Developer/CoreSimulator/

Here, they are listed as directories with UUID names. Use sort by 'Date modified' to find the latest one. Inside navigate to:

/data/Containers/Data/Application/

Here you will get a list of all the applications on that device. You can again sort this to get the latest app.

NOTE: Xcode changes the directory name every time you run the app, so don't rely on making alias/short cuts on desktop.

The easiest way is to use the app here, which does everything automatically.

Excruciate answered 28/11, 2014 at 11:49 Comment(0)
R
1

I created this script that will zip the latest app built for any simulator and zip it to the desktop.

https://gist.github.com/Gerst20051/8ca49d5afbf09007b3696fab6e9f425c

#!/bin/bash

DESTINATION_DIR="$HOME/Desktop"
APP_PATH=$(find ~/Library/Developer/CoreSimulator/Devices/*/data/Containers/Bundle/Application/*/*.app -type d -maxdepth 0 -print0 | xargs -0 ls -td | head -n1)
APP_DIRNAME=$(dirname "$APP_PATH")
APP_BASENAME=$(basename "$APP_PATH")
FILE_NAME="${APP_BASENAME%.*}"

cd "$APP_DIRNAME"
zip -qr "$DESTINATION_DIR/$FILE_NAME.zip" "$APP_BASENAME"
Raynaraynah answered 23/11, 2016 at 18:13 Comment(0)
V
1

In Swift 4 or Swift 5 you can use NSHomeDirectory().

The easiest way in Xcode 10 (or Xcode 11) is to pause your app (like when it hits a breakpoint) and run this line in the debugger console:

po NSHomeDirectory()

po stands for print object and prints most things

Varityper answered 16/7, 2019 at 16:59 Comment(0)
W
0
 1.   NSTemporaryDirectory() gives this:

    /Users/spokaneDude/Library/Developer/CoreSimulator/Devices/1EE69744-255A-45CD-88F1-63FEAD117B32/data/Containers/Data/Application/199B1ACA-A80B-44BD-8E5E-DDF3DCF0D8D9/tmp

 2. remove "/tmp" replacing it with "/Library/Application Support/<app name>/"  --> is where the .sqlite files reside
Wednesday answered 1/2, 2015 at 19:45 Comment(0)
A
0
  1. With Swift 4, you can use the code below to get your app's home directory. Your app's document directory is in there.

    print(NSHomeDirectory())

  2. I think you already know that your app's home directory is changeable, so if you don't want to add additional code to your codebase, SimPholder is a nice tool for you.

  3. And further more, you may wonder is there a tool, that can help you save time from closing and reopening same SQLite database every time after your app's home directory be changed. And the answer is yes, a tool I know is SQLiteFlow. From it's document, it says that:

    Handle database file name or directory changes. This makes SQLiteFlow can work friendly with your SQLite database in iOS simulator.

Ashy answered 1/6, 2018 at 6:17 Comment(0)
F
0

Here is the sh for last used simulator and application. Just run sh and copy printed text and paste and run command for show in finder.

#!/bin/zsh

lastUsedSimulatorAndApplication=`ls -td -- ~/Library/Developer/CoreSimulator/Devices/*/data/Containers/Data/Application/*/ | head -n1`

echo $lastUsedSimulatorAndApplication
Funda answered 9/8, 2018 at 20:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.