0

I am developing an iOS application with Objective-C and CoreData. Where can I locate the sqlite file generated on the iOS device?

trojanfoe
  • 120,358
  • 21
  • 212
  • 242
joan
  • 2,407
  • 4
  • 29
  • 35

3 Answers3

1

IF the store uses a persisted file, you can even get it in code

//get you context, the coordinator, attached stores
NSManagedObjectContext *moc = [MyDataStore sharedDataStore].mainManagedObjectContext; //however you get the MOC
NSPersistentStoreCoordinator *coordinator = moc.persistentStoreCoordinator;
NSArray<NSPersistentStore*> *stores = coordinator.persistentStores;

//log it
for (NSPersistentStore *store in stores) {
    NSLog(@"%@", store.URL);
}
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
1

For XCode 8.0 (iOS 10)

Path to the persistent store created by NSPersistentContainer can be seen by adding following code in existing (didFinishLaunchingWithOptions) method in your AppDelegate:-

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) // look for doc. directory

    return true
}

Go to the path in the print log then go to the /Library/Application Support folder. Here is the sample path of .sqlite(persistent store) file:

/Users/Ashish/Library/Developer/CoreSimulator/Devices/F04D26BC-0AA9-4E25-87CC-E635BE86293A/data/Containers/Data/Application/69873117-6AB0-4491-B3BA-302FE63050FB/Library/Application Support

Nupur Sharma
  • 1,106
  • 13
  • 15
0

It's wherever you decided to put it. You don't even need to look it up, because you already have that information.

When you call addPersistentStoreWithType:configuration:URL:options:error:, the URL argument that you pass in is the location of the persistent store. You could look it up by the NSManagedObjectContext and the NSPersistentStoreCoordinator, but why do that when the answer is already there in your app?

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170