XCode4 - where to look for sqlite file created by core data

前端 未结 4 891
春和景丽
春和景丽 2020-12-30 12:30

I have just started using core data. I want to setup a pre-populated db. I read somewhere that core data creates a sqlite file when a core data app is run. I don\'t know whe

4条回答
  •  天命终不由人
    2020-12-30 13:27

    Follow these steps:

    1. In your applicationDocumentsDirectory function in AppDelegate.swift add this code:

      let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)

      // Look for this in the console, this will print out the location of the sqlite database, which you can then open with an SQLite viewer

      print("urls.last \(urls.last)")

    2. Look for this in the console, this will print out the location of the sqlite database, open your terminal and open whatever_the_location_path_was

    3. Download SQLite viewer http://sqlitebrowser.org/

    4. Right click the yourapp.sqlite file in the folder, choose Open With sqlitebrowser that you downloaded

    Cheers!

提交回复
热议问题