How can I check what is stored in my Core Data Database?

后端 未结 17 2167
北恋
北恋 2020-12-12 14:35

I am making an app that relies on Core Data. I am able to enter data into a text field and store it.

But I need to know if the data is being stored.

I am try

相关标签:
17条回答
  • 2020-12-12 14:47

    As Far as macOS Sierra version 10.12.2 and XCode 8 is concerned

    The folder should be here:

    /Users/$username$/Library/Developer/CoreSimulator/Devices/$DeviceID$/data/Containers/Data/Application/$ApplicationID$/Library/Application Support/xyz.sqlite

    To get the device id - Open terminal and paste:

    instruments -s devices

    0 讨论(0)
  • 2020-12-12 14:48

    An easy and convenient way to locate the Core Data database and to view and analyse the content, is by using a tool like Core Data Lab.

    More info here: https://betamagic.nl/products/coredatalab.html

    Disclaimer: I'm the creator of this tool.

    0 讨论(0)
  • 2020-12-12 14:49

    1) Get path of sql database of your simulator.

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSLog(@"%@", [paths objectAtIndex:0]);
    

    2) Open Finder. Press Cmd+Shift+G. Paste something, that you got from paragraph 1. Ex:

    /Users/USERNAME/Library/Developer/CoreSimulator/Devices/701BAC5F-2A42-49BA-B733-C39D563208D4/data/Containers/Data/Application/DCA9E9C7-5FEF-41EA-9255-6AE9A964053C/Documents
    

    3) Download in AppStore programm like SQLPro.

    4) Open file in folder with name "ProjectName.sqlite".

    GOOD JOB! You will see something like this:

    0 讨论(0)
  • 2020-12-12 14:51

    Swift 4, 5

    Add this line in AppDelegate >> didFinishLaunchingWithOptions function:

    print("Documents Directory: ", FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last ?? "Not Found!")
    

    Your modelName.sqlite file will be there.

    You can open it with any SQLite browser tools like http://sqlitebrowser.org/ that is free.

    0 讨论(0)
  • 2020-12-12 14:54

    Since no one has pointed out, how to get the sqlite DB from the physical device.

    Here is how to get the application data:

    Browse the files created on a device by the iOS application I'm developing, on workstation?

    After opening the .xcappdata file (right click > Show Package Content), you will usually find the DB file at the AppData/Library/Application Support folder.

    0 讨论(0)
  • 2020-12-12 14:55

    The other solutions are either old or does not direct you easily or quickly to the SQLite files, so I came up with my own solution using FileManager.SearchPathDirectory.applicationSupportDirectory that gets the exact path where the sqlite file will be.

    func whereIsMySQLite() {
        let path = FileManager
            .default
            .urls(for: .applicationSupportDirectory, in: .userDomainMask)
            .last?
            .absoluteString
            .replacingOccurrences(of: "file://", with: "")
            .removingPercentEncoding
    
        print(path ?? "Not found")
    }
    

    whereIsMySQLite() will print the path which you can simply copy-paste on your Mac here:

    Finder > Go > Go to folder

    0 讨论(0)
提交回复
热议问题