Main data file Location iOS 10

I am trying to use SQLite Browsers to view my Core Data objects. I can not find where the main data stores its sql file. I looked into the application documents folder, but there is nothing there.

Do you know where the main data in iOS 10 (simulator) saves its SQLite files?

+12
ios ios10 swift ios-simulator core-data
source share
6 answers

I tested it on Xcode 8 Swift 3 OS macOS Sierra

Ios 10

In your app, Appdelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) print(urls[urls.count-1] as URL) return true } 

1. The constant .documentDirectory says that we are looking for a directory of documents

2. Permanent .userDomainMask to limit our search to the sandbox of our application.

Exit

 file:///Users/Ashok/Library/Developer/CoreSimulator/Devices/F629F99F-C745-46EB-8A11-01BC9FF1E592/data/Containers/Data/Application/3B373C93-71A2-46E9-8AF7-EF407C39429F/Documents/ 

Click "Go" → "Go to folder" → "Insert path" → "Hit entry"

enter image description here

Then go to the library -> Application Support -> filename.sqlite

enter image description here

Edited

OR

open your terminal and type find ~ -name 'HitTest.sqlite' and press enter.

 Ashoks-MacBook-Pro:Desktop Ashok$ find ~ -name 'HitTest.sqlite' /Users/Ashok/Library/Developer/CoreSimulator/Devices/F629F99F-C745-46EB-8A11-01BC9FF1E592/data/Containers/Data/Application/3B373C93-71A2-46E9-8AF7-EF407C39429F/Documents/HitTest.sqlite 

From the above, you can clearly see the path to your sqlite db

You can use DB Browser for SQLite to open.

+28
source share

Just try this, I did not test it on ios 10, but it worked in all previous versions

Product> Schema> Edit Schema> Run> Arguments

Add this argument to " Arguments passed at startup "

-com.apple.CoreData.SQLDebug 1

Each time the application starts, it will print the database path .

+12
source share

Swift 3.x

Locate didFinishLaunchingWithOptions in the AppDelegate file and add this line.

 let path = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true) print("\(path)") 
+6
source share

For XCODE 8.0 (iOS 10): -

Permanent .sqlite storage path:

/ Users/Ashish/Library/Developer/CoreSimulator/Devices/"YourDeviceId"/data/Containers/Data/Application/"Application Id"/Library/Application Support/"FileNamePassedInPersistentContainer.sqlite"

0
source share

Since the location of the master data file of your application can be changed , after you find it, you can use a SQLite browser, such as SQLiteFlow, to view the contents of the master data file. The reason is simple, it can handle SQLite file location changes. From the SQLiteFlow document:

Processing database file name or directory changes. This allows SQLiteFlow to work with your SQLite database in the iOS simulator.

0
source share

For Swift 5

 func getCoreDataDBPath() { let path = FileManager .default .urls(for: .applicationSupportDirectory, in: .userDomainMask) .last? .absoluteString .replacingOccurrences(of: "file://", with: "") .removingPercentEncoding print("Core Data DB Path :: \(path ?? "Not found")") } 

This will give a detailed path to the sqlite file (dbname.sqlite)

 print("CoreData path :: \(self.getCoreDataDBPath())") 

Note. Click "Go" → "Go to folder" → "Insert path here" → "Enter".

0
source share

All Articles