Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View contents of Core Data

Tags:

ios

core-data

I want to be able to see the contents of the Core Data contained in my iPhone simulator app from the command line.

I've tried "cd'ing" into ~/Library/Application Support/iPhone Simulator/7.0/Applications and then using find . -name MyAppName to find which of these directories contains my app:

29EB3FF9-4691-474D-8B05-AB168899D528 4C25697B-04D9-4B48-BE5E-D1E9B2E03381 A1DF7916-AE39-4367-BFD2-22A8BAA2AFD2 BDB577A8-0BCF-4E58-896B-D4E704F261D0 CC3CC638-E39D-4AE7-8580-4E8BBD375DC4 D11D7C57-5578-4531-85BB-71AE6DD68B2F

Then I navigate to the "Documents" folder inside this folder, but the only "sqlite" files I see are CoreDataTabBarTutorial.sqlite CoreDataTabBarTutorial.sqlite-shm CoreDataTabBarTutorial.sqlite-wal. (EDIT: I had actually named my persistentStoreCoordinator's URL to CoreDataTabBarTutorial.sqlite).

I'm sure that my objects get inserted to "Core Data", but it appears they don't persist between launches of Interface Builder. I'm trying to debug that.

like image 972
Rose Perrone Avatar asked Aug 17 '13 15:08

Rose Perrone


1 Answers

In order to Know the path of your sqlite file , follow the these steps

1) Open AppDelegate of your project.

2) There must exists a var with declaration as (only if you have checked Use CoreData while creating your project):

lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {

3) Find this a line similar to

let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("SingleViewCoreData.sqlite")

4) print this url as

print("persistentStoreCoordinator url : (url)")

5) Run your app find this url in console 6) copy that url , open terminal , type cd then paste this url url be like

(file:///Users/prnjls/Library/Developer/CoreSimulator/Devices/A2B99983-4B71-4708-A515-7A87463ECF0C/data/Containers/Data/Application/F70EF393-FBF7-4598-B28B-9DAACBFE46F8/Documents/SingleViewCoreData.sqlite)

7) Download and install a free app to view sqlite data here

8) Open On Liya Click on File -> New -> select sqlite in Database type -> click on the icon near it -> navigate to that sqlite file using the path you copied.

9) You Can find all your entities you have saved tap on any Entity name and click on Run SQL Command . That's it . Hope it will help someone anyway.

like image 71
Preeti Rani Avatar answered Nov 15 '22 11:11

Preeti Rani