Where is my sqlite data stored in iOS simulator?
Asked Answered
F

9

12

I created an iPad app on xCode(using PhoneGap) with sqlite plugin, stored data, and then when I want to view the data I stored I couldn't find where I saved it. According to my online research, it should be under /Library/Developer/CoreSimulator/Device

However when I navigate to the /CoreSimulator file, I don't see a sub-folder "/Device", just "/Profiles/Runtimes"?

When I reopen the app and wanted to check my stored data I couldn't see them aswell.

Familiar answered 31/8, 2016 at 5:22 Comment(3)
see this #1108576Harty
see this also #4647192Harty
I've seen those posts, but neither helped. As stated before, I can't see the /Device sub-folder nor the /iPhone Simulator sub-folder under /Application SupportFamiliar
D
19
let dirPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)

let docsDir = dirPaths[0]

print(docsDir)

Get the path printed in the debugger, copy it, open finder and press Cmd+Shift+G. A dialog box of Go to folder will open and paste the path and hit enter. You will be navigated to that folder. All the documents created in your project will be present in that folder including the .sqlite file. Don't try to navigate to that folder manually. Chances are you are looking at the wrong folder.

Also don't worry when every time Xcode prints a different path. Its a change brought from Xcode 6 onwards. Don't know why. But your files(those documents) will probably stay updated.

Duluth answered 31/8, 2016 at 8:18 Comment(0)
W
8

This is My app's folder:

/Users/***/Library/Developer/CoreSimulator/Devices/4420949E-AD14-4A4F-9153-53891734BEB9/data/Containers/Data/Application/0A18183F-2CF6-4D72-938D-DF59CFA48CCF

you can find your app's folder by the following code:

NSString *strPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

Or just add a plugin: NCSimulatorPlugin

Wonacott answered 31/8, 2016 at 5:42 Comment(0)
P
6

Standalone app

As of Swift 4+, add a breakpoint somewhere to stop your code, then in the console:

po FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!

You can then find an sqlite file in one of the subdirectories. It can be different, depending on iOS versions.

If you are using an App Group (or alternate method for standalone app)

If data is shared among multiple apps, the method above will not work. But you can also follow this method if you just did not find the sqlite file.

You can get Xcode to print the path:

  1. Open Product > Scheme > Edit Scheme > Run > Arguments
  2. Add -com.apple.CoreData.SQLDebug 1 argument in "Arguments Passed on launch"

Next time you launch the app, you should see something like this in the log output:

CoreData: annotation: Connecting to sqlite database file at /Users/***/Library/Developer/CoreSimulator/Devices/****/data/Containers/****/YourAppName.sqlite

As a bonus, you'll also get a bunch of other Core Data debug info.

Photophobia answered 22/7, 2021 at 11:32 Comment(0)
A
3

I have the same issue when using core data,

Some how i solve the problem with following steps:

  1. print the url of my sqlite file in console

  2. copy the url

  3. open a finder and press cmd + shift + G

  4. paste the url and press enter

Then the sql file will be showed.

I haven't use PhoneGap, but if you can print the sql file url from SDK ,

you can find the file as well.

Acrolein answered 31/8, 2016 at 5:41 Comment(2)
print the url of my sqlite file in console how to do thatPostmaster
If you uses version above iOS 10 you can print persistentContainer.defaultDirectoryURL() . if you use older version , you can print url when add NSSQLiteStoreType persistentStore.Acrolein
A
2

If you don't want to (or can't) print the app's directory, you can do a simple search in Finder.

In Finder, open this folder: /Users/{yourUsername}/Library/Developer/CoreSimulator/Devices

If you know the name of your database, use Finder's search to search for the database's filename.

OR

If you don't know the name of the database, use Finder's search to search for "LocalDatabase". There might be several "LocalDatabase" directories that appear in the search results, but if you look through them you should be able to narrow it down to the database you're looking for by its last modified date.

Amnesia answered 20/4, 2018 at 0:24 Comment(0)
J
0

On your app's console type "po NSUserDirectory" it will return the url where all your simulator files are sitting.

1.copy that url.

2.on your machine goto "Go to folder" paste the url.

3.Library > Application support

That is where your sql file is sitting.

Hope it helps!

Jermaine answered 4/8, 2017 at 8:9 Comment(0)
A
0

To be precise, you can find local db in this path.

/Users/jacob/Library/Developer/CoreSimulator/Devices/BBD9ED33-F903-4349-BB7F-A5A6F89DACC8/data/Containers/Data/Application/CF308117-7C0E-4A77-872F-93A02EA76F5F/Library/LocalDatabase

Where, BBD9ED33-F903-4349-BB7F-A5A6F89DACC8 and CF308117-7C0E-4A77-872F-93A02EA76F5F can be changed.

Airminded answered 11/4, 2018 at 5:12 Comment(0)
F
0

The accepted answer and other answers doesn't account for AppGroups. The easiest way to find the exact location is to get the defaultDirectoryURL() from your NSPersistentContainer.

You can check the documentation here.

Points to note:

  • This is a class func and can be overridden by a subclass. So make sure to call this on subclass if your app is using one.
  • This method returns the exact location for each platform.
Feminism answered 19/2, 2023 at 1:12 Comment(0)
A
0

Adding to this, once you get to the correct Library folder (which was hidden for me, I had to use CMD + SHIFT + G), you can then open up a folder in terminal and run the following command:

find . -type f -name "name-of-your.db"
Antimicrobial answered 15/8, 2024 at 22:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.