Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data file's Location iOS 10

I am trying to us SQLite Browsers to see my Core Data objects. I am not able to find where does the core data save its sql file. I looked into the app documents folder but there is nothing there.

Do you know where does the core data in IOS 10(simulator) save its SQLite files on?

like image 570
Idan Aviv Avatar asked Sep 27 '16 10:09

Idan Aviv


People also ask

Where is Core Data saved?

The persistent store should be located in the AppData > Library > Application Support directory. In this example you should see a SQLite database with extension . sqlite. It is possible that you don't see the persistent store in the Application Support directory.

What is Core Data in iOS?

Core Data is a framework that you use to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence.

Should I use Core Data iOS?

The next time you need to store data, you should have a better idea of your options. Core Data is unnecessary for random pieces of unrelated data, but it's a perfect fit for a large, relational data set. The defaults system is ideal for small, random pieces of unrelated data, such as settings or the user's preferences.

What is codegen in Core Data?

Class DefinitionThis configuration is the default Codegen configuration when you create an entity in the data model editor. With this configuration, Xcode will automatically generate the required NSManagedObject subclass as part of the project's derived data.


2 Answers

I tested it on XCode 8 Swift 3 OS macOS Sierra

IOS 10

In Your 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 we are looking for Document directory

2. The constant .userDomainMask to restrict our search to our application's sandbox.

output

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

Click on Go -> Go to Folder -> Paste Path -> Hit Enter

enter image description here

Then Go to Library -> Application Support -> filename.sqlite

enter image description here

Edited

OR

open your terminal and type find ~ -name 'HitTest.sqlite' and hit 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 above output you can clearly see the path of your sqlite db

You can use DB Browser for SQLite to open.

like image 77
Ashok R Avatar answered Sep 28 '22 22:09

Ashok R


Just try this i haven't check it on ios 10 but its working in previous all versions

Product > Scheme > Edit Scheme > Run > Arguments

Add this argument in "Arguments Passed on launch"

-com.apple.CoreData.SQLDebug 1

Everytime when application launches It will print path to database See This argument look like this

like image 38
Jitendra Modi Avatar answered Sep 28 '22 23:09

Jitendra Modi