Sqlite File Location Core Data Sqlite File Location Core Data ios ios

Sqlite File Location Core Data


I managed to locate the sqlite file, and its in this path now:

Library/Developer/CoreSimulator/Devices/(numbers and letters)/data/Containers/Data/Application/(numbers and letters)/Documents/

(numbers and letters) stands for a folder that would be unique to your app/computer, but would look like this: 779AE2245-F8W2-57A9-8C6D-98643B1CF01A

I was able to find it by going into appDelegate.m, scrolling down to the

- (NSURL *)applicationDocumentsDirectory 

method, and NSLogging the return path, like this:

// Returns the URL to the application's Documents directory.- (NSURL *)applicationDocumentsDirectory{    NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory  inDomains:NSUserDomainMask] lastObject]);    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; }

This will give you your unique path, making it easier for you, because it is tricky locating it with the 2 unnamed folders/strings of letters and numbers.

Swift 4.2:

let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)print(paths[0])


None of the answers mentioned the simplest way to actually get the location of the DB file.

It doesn't even require you to modify your source code, as it's a simple run time switch in XCode.

  1. Choose Edit Scheme... next to the Run button.

    edit scheme

  2. Select Run / Arguments and add the following two options:

    -com.apple.CoreData.SQLDebug 1-com.apple.CoreData.Logging.stderr 1

    option

  3. Run the app, and you'll see in the logs:

    logs


Try this Simple 3 Step

  1. Copy the following code in didFinishLaunchingWithOptions your appdelegate.m and add a break point before the NSLog()

    (BOOL)application:(UIApplication *)application  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSLog(@"%@",[paths objectAtIndex:0]); }

Or in Swift:

let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)print(paths[0])

enter image description here

2.Open Finder->Go -> Go to folder and paste the path copied from step 1

enter image description here

3. Yah!!! You are in your Destination.