How to view data stored in Core Data?
I'm creating a Core Data model f开发者_Python百科or my application. I would like to be able to look inside it to see what I have stored in there.
Is there an easier way than searching for the backing store (mine should be SQLite) and reading it from there? Doesn't seem very Apple-esque.
Once your app has run in the simulator and created the persistent store file, you can find the file in your app's Documents directory.
Your app data will be folder inside (~ is your home directory):
~/Library/Developer/CoreSimulator/<device>
In versions prior to XCode 6, the path was:
~/Library/Application Support/iPhone Simulator/User/Applications/
I sort by "Date Modified" to find the app that I just built.
For viewing a SQLite file, check out Base and/or Core Data Editor.
You can also use FireFox's Add-on tool SQLite Manager (FREE). I use it and it works well.
If you are using iOS 10 & Swift get it into your AppDelegate.swift:
let container = NSPersistentContainer(name: "***")
print(container.persistentStoreDescriptions.first?.url)
Then you'll see something like that:
Optional(file:///Users/<SomeUser>/Library/Developer/CoreSimulator/Devices/956F0003-5DA4-4588-97C1-A9A83767F341/data/Containers/Data/Application/9765FDE1-6971-4706-987B-96FBD3F462BF/Library/Application%20Support/***.sqlite)
You can try a little free tool called CoreDataPro. Pretty nice. Here
Core Data Lab is a dedicated Core Data viewer that offers everything to view and analyze the Core Data database of your app, like automatic search for databases, data change tracker, simulator browser, a predicate editor, data editor, a built-in web and image content viewer, and much more.
Info page: https://betamagic.nl/products/coredatalab.html
Free 14-trial: https://betamagic.nl/downloads/Core%20Data%20Lab%20Trial.zip
Diclaimer: I'm the creator of this tool.
I found a free version here:
http://sourceforge.net/projects/sqlitebrowser/files/sqlitebrowser/2.0%20beta1/sqlitebrowser_200_b1_osx.zip/download
Update to this thread, The iphone simulator location has been moved to a different location in Xcode7 and Xcode8. It is now in:
~/Library/Developer/CoreSimulator/...
where ~ is your home directory.
Any of the previous solutions will still work, but you won't be able to find the correct folder if you use the previous links.
Also try sqlite database browser. its free and reflects that fact. very useful though!
cheers.bo
I created a macOS app to browse your Core Data content. It hides Core Data implementation as you see when you use a SQLite browser. Also you can list all your latest run apps and simulators, with this you can easily find the app you are looking for. More info here:
http://www.microedition.biz/simMagnifier
It has other features like access Simulator's folders such as Documents, Application Support, etc. You can check the content of NSUserDefaults too.
The app is not free sorry! but at least you have a 7 days trial.
Here is the full path, apparently it changed since gerry3's answer
~/Library/Application Support/iPhone Simulator/<Simulator>/Applications/<ApplicationID>/Documents/<NAME>.sqlite
So a correct path would like this:
~/Library/Application Support/iPhone Simulator/7.1-64/Applications/C1F3C2E5-987A-4DF7-91EF-955AE6E52621/Documents/TestApp.sqlite
3 Easy Steps
install liya application, its free, Size 3.1 MB, so installs in 1 minute.
Link https://itunes.apple.com/us/app/liya/id455484422?mt=12.Open Finder, Press "Ctrl + G" OR "CMD + Ctrl + G", Paste ~/Library/Developer/
In Developer Folder, search for your Core Data model name(eg. MyProjectModel).
Open
MyProjectModel.d
file Or 'MyProjectModel.sqlite' using liya. In liya, select a table, Click on "Run SQL Command".
Done.
精彩评论