Sqlite File Location Core Data

2019-01-03 21:35发布

Typically, the sqlite store file for core data apps is located in

Library>Application Support>iPhone Simulator>7.1(or whichever version you are using)>Applications>(Whichever folder contains your app)>Documents

folder, but I can't find it in IOS 8. I would assume they would just add an 8.0 folder inside the iPhone Simulator folder, but it's not there. Has anybody been able to locate it?

19条回答
Ridiculous、
2楼-- · 2019-01-03 21:53

For Swift 3.0

let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
print(paths[0])

you can get location of Coredata in Xcode 8.2

查看更多
叛逆
3楼-- · 2019-01-03 21:53

Like James Snook I created my own script to provide easier access to the simulator apps. I think it can be handy to many people getting here, other than me.

Unlike his script, mine is not a search tool, it creates a complete (and human readable) folder structure with all the devices/runtimes, and puts soft links to the apps in them.

You can get it in this Gist.

Run it every time you install an app in the simulator, or just run it every time you are going fetch an app for any reason (it will update, and open the devices folder in Finder).

查看更多
smile是对你的礼貌
4楼-- · 2019-01-03 21:54

For swift 3

print(NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last! as String)
查看更多
我想做一个坏孩纸
5楼-- · 2019-01-03 21:55

I managed to locate the sqlite file, and its in this path now:

Library/Developer/CoreSimulator/Devices/(numbers and letters)/data/Containers/Data/Application/(numbers and letters)/Documents/

(numbers and letters) stands for a folder that would be unique to your app/computer, but would look like this: 779AE2245-F8W2-57A9-8C6D-98643B1CF01A

I was able to find it by going into appDelegate.m, scrolling down to the

- (NSURL *)applicationDocumentsDirectory 

method, and NSLogging the return path, like this:

// Returns the URL to the application's Documents directory.
- (NSURL *)applicationDocumentsDirectory
{
    NSLog(@"%@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory  inDomains:NSUserDomainMask] lastObject]);

    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
 }

This will give you your unique path, making it easier for you, because it is tricky locating it with the 2 unnamed folders/strings of letters and numbers.

Swift 4.2:

let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
print(paths[0])
查看更多
我欲成王,谁敢阻挡
6楼-- · 2019-01-03 21:58

Based on Michaels answers, this is for Swift 3

    func applicationDirectoryPath() -> String {
        return NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last! as String
    }
查看更多
7楼-- · 2019-01-03 21:58

You can use following code.

   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    **print(persistentContainer.persistentStoreDescriptions)**
    return true
}

It will print location of core data persistent storage i.e sqlite

查看更多
登录 后发表回答