2

When i use to work with core data i often use that code to show me path to .sqlite database:

NSLog(@"%@ path-core",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory  inDomains:NSUserDomainMask] lastObject]);

However, when i add Magical Record to my project, i used this instead:

NSLog(@"magical record path to SQLite base %@", [NSPersistentStore MR_defaultLocalStoreUrl]);

Which print path:

/Users/Necrosoft/Library/Developer/CoreSimulator/Devices/68A05D98-7949-4F90-BFB9-9C8A368F411B/data/Containers/Data/Application/7EC45D6A-B20E-4EC2-B657-1425F714518F/Library/Application%20Support/MyApp/CoreDataStore.sqlite

But i cant find CoreDataStore.sqlite. When i try "go to" with finder, i simply find an empty folder. But i guess there is actually .sqlite db stored in here. So how can i access it?

UPDATE: In Application Support folder there is actual 4 items, but i see only 3, 1 missing (hiding) is the one i need. How to get it?

enter image description here

Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107
  • this may help you but it is in swift http://stackoverflow.com/questions/25434354/nslogging-println-sqlite-db-file-location-in-swift/40325883#40325883 – Ashok R Jan 06 '17 at 15:17
  • Look how is constructed `MR_defaultLocalStoreUrl` in the code: with `MR_directory:NSApplicationSupportDirectory` not `NSDocumentDirectory`, which can be seen in the path `/Library/Application%20Support`. Just follow that logic. It appends also the app name `[[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey];`. Source: https://github.com/magicalpanda/MagicalRecord/blob/master/MagicalRecord/Categories/NSPersistentStore%2BMagicalRecord.m – Larme Jan 06 '17 at 15:17
  • @Larme so how can i access this file?.. – Evgeniy Kleban Jan 06 '17 at 15:33
  • `NSString *path = [[[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject] stringByAppendingPathComponent: [[[NSBundle mainBundle] infoDictionary] valueForKey:(NSString *)kCFBundleNameKey]];`? – Larme Jan 06 '17 at 15:35
  • @Larme what is kCFBundleNameKey? – Evgeniy Kleban Jan 06 '17 at 15:36
  • https://developer.apple.com/reference/corefoundation/kcfbundlenamekey And from the previous code, just add `CoreDataStore.sqlite` at the end I guess. Oh, I misread your question, do like Ashok said: http://stackoverflow.com/questions/39722844/core-data-files-location-ios-10/40103564#40103564 – Larme Jan 06 '17 at 15:37
  • @Larme for some reason .db stored in Application Support folder is an empty and has different name. I guess it may be something related to Magical Record inner usage. – Evgeniy Kleban Jan 06 '17 at 15:42
  • Can't Find iPhone Simulator's SQLite Database : Using Magical Record http://stackoverflow.com/questions/16426536/cant-find-iphone-simulators-sqlite-database-using-magical-record – Ashok R Jan 06 '17 at 15:47
  • i feel you have to look in to this https://github.com/magicalpanda/MagicalRecord/issues/91 – Ashok R Jan 06 '17 at 16:06

1 Answers1

2

The ultimate goal for you is finding CoreDataStore.sqlite file.

open your terminal and type find ~ -name 'CoreDataStore.sqlite' and hit enter.

Ashoks-MacBook-Pro:Desktop Ashok$ find ~ -name 'CoreDataStore.sqlite'
/Users/Ashok/Desktop/CoreDataStore.sqlite

From above output you can clearly see the path of your sqlite db

I hope it helps:-)

Ashok R
  • 19,892
  • 8
  • 68
  • 68