I am developing an iOS application with Objective-C and CoreData. Where can I locate the sqlite file generated on the iOS device?
-
sqlite file wil be in the app sandbox for a device!!! – Teja Nandamuri Feb 11 '16 at 17:03
-
you can log the document directory path within the code!! – Teja Nandamuri Feb 11 '16 at 17:04
-
Possible duplicate of [Xcode 6 iPhone Simulator Application Support location](http://stackoverflow.com/questions/24290989/xcode-6-iphone-simulator-application-support-location) – Shehzad Ali Feb 11 '16 at 17:17
3 Answers
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);
}

- 49,552
- 17
- 113
- 135
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

- 1,106
- 13
- 15
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?

- 69,312
- 10
- 146
- 170