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条回答
姐就是有狂的资本
2楼-- · 2019-01-03 22:10

None of the answers mentioned the simplest way to actually get the location of the DB file.

It doesn't even require you to modify your source code, as it's a simple run time switch in XCode.

  1. Choose Edit Scheme... next to the Run button.

    edit scheme

  2. Select Run / Arguments and add the following two options:

    -com.apple.CoreData.SQLDebug 1
    -com.apple.CoreData.Logging.stderr 1
    

    option

  3. Run the app, and you'll see in the logs:

    logs

查看更多
Summer. ? 凉城
3楼-- · 2019-01-03 22:12

For SWIFT 3 :

Copy paste this code in didFinishLaunchingWithOptions

 print(NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last! as String)
查看更多
狗以群分
4楼-- · 2019-01-03 22:15

I wrote a bash script for finding the location of your Application folder and the Application data folder within a simulator, you can download it here. Once you have unzipped the script you can navigate to the folder the script is in and use it. If you call it with no options it will give you a list of installed iOS simulators. You can then use the options to find your program. Writing:

./simulatorAppFolders -s "iPad Air" -i iOS-8-0 -a <MyApp>

will find the application folder and home area folder for your app on the iPad Air iOS 8 simulator. Here's an example:

MacBook-Air:_posts user$ ./simulatorAppFolders -s "iPad Air" -i iOS-8-0 -a MyApp
App folder = /Users/james/Library/Developer/CoreSimulator/Devices/6A9DEE93-FAEF-4BF4-9989-BC14CD38AEA0/data/Containers/Bundle/Application/8F64CD7F-A227-43D6-98AC-41D3919827CB
dataFolder = /Users/james/Library/Developer/CoreSimulator/Devices/6A9DEE93-FAEF-4BF4-9989-BC14CD38AEA0/data/Containers/Data/Application/96C40A21-5A5C-4399-839C-B155B8A72932

Update

There's an update to the original script which allows you to search based on the device type using a -d option. I've also written another script which makes a series of sensibly named folders so you can find your application and application documents. This script will make a folder called iOS_SIMULATORS in your home area and you can easily navigate to your application from there.

查看更多
爷、活的狠高调
5楼-- · 2019-01-03 22:16

I was able to locate simulators folder with the next console output:

NSLog(@"app dir: %@",[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);

in my case it was (Xcode 6 beta)

app dir: file:///Users/user/Library/Developer/CoreSimulator/Devices/D00C56D4-DDA3-47B0-9951-27D3B9EC68E8/data/Applications/6ABF3E54-37F5-4AD1-A223-F7467F601FB6/Documents/
查看更多
【Aperson】
6楼-- · 2019-01-03 22:16

Swift 4.x

    let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
    print(paths[0])
查看更多
够拽才男人
7楼-- · 2019-01-03 22:18

If you haven't specified any directory then you can use the below code to print default directory:

print(NSPersistentContainer.defaultDirectoryURL())

查看更多
登录 后发表回答