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
I found the best way to find and open the .sqlite database is use this script:
lsof -Fn -p $(pgrep YOUR_APP_NAME_HERE) | grep .sqlite$ | head -n1
For whatever reason, the output on my Mac always has an extra n
character, so I had to copy and paste it to open
command. Feel free to modify the above command if you've figured out the right command.
For the best SQLite browser, I'd recommend TablePlus.
Adopted from: https://lukaszlawicki.pl/how-to-quickly-open-sqlite-database-on-ios-simulator/
An answer for a noobs as I was, I spent quite a lot of time in figuring it out. Steps I followed are :
Command(Windows) + Shift + G
.~/Library/Developer
my.db
in SQLite.In Swift 3, you have the the NSPersistentContainer
and you can retrieve the path from there like this:
persistentContainer.persistentStoreCoordinator.persistentStores.first?.url
(Assuming you are only using one persistent store)
Sorry for the late answer
i wasnt able to find it in the iphone simulator folder. Then i found out the folder by printing the doc path in log .
Code:
NSLog(@"The Path is %@",
[[[NSFileManager defaultManager] URLsForDirectory:
NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]);
and the path turns out be like this :
// /Users/<username>/Library/Developer/CoreSimulator/Devices/<app specific id>/data/Containers/Data/Application/<id>/Documents/coredata.sqlite
Here is my solution(works on iOS 9):
I use an automator/bash script that open the database in sqllitebrowser. the script finds the latest installed app in the simulator. Instructions:
cd ~/Library/Developer/CoreSimulator/Devices/ cd `ls -t | head -n 1`/data/Containers/Data/Application cd `ls -t | head -n 1`/Documents open -a DB\ Browser\ for\ SQLite ./YOUR_DATABASE_NAME.sqlite
As said before, you can use the sqllite command line tool.
However, you can also set the debug flag, which will dump out all sql commands as they execute through core data.
Edit the scheme, and add this in the "Arguments Passed on Launch"
-com.apple.CoreData.SQLDebug 1