Core Data loses database file after Xcode upgrade

I have an iOS app that uses core data. I entered data into it two days ago, and everything was worlking fine then. I closd the app, then re-opened it, and the data was still there as expected. Yesterday, I updated Xcode to 9.4, and when I opened my app, the data was gone. The app prints out the database location, so I went there to look at the SQLite file, which was 25 kB in size. Opening that with DB Browser for SQLite also showed no data. However, when I looked through the folders in the Devices folder (~/Library/Developer/CoreSimulator/Devices), I found another folder that showed it had been updated the day before. When I followed that path to the end, I found another sqlite database that did contain my data. So, it seems that Xcode has "forgotten" where it put my data. I don't know if it's relevant or not, but the new version of Xcode originally open the app with the iPhone 8 simulator, whereas I had been opening it in an iPad simulator in the previous version. Switching back to the iPad simulator did not remedy the situation.


This happened to me once before in March or maybe April. Unfortunately, I don't remember if I did an upgrade of Xcode at that time as well.

So, you are working in simulator, not a real device ?


Take care, each XCode simulator has its own storage area. If you change to another device in simulator, you will not see data from the other device simulator.

Confirm the path to derived data using Xcode's preferences.

Yes, currently, I'm still testing and launching the app through Xcode. I realize that each simulator has its own storage area, but I would expect that going back to the same simulator I used the day I added the data should work. Could the problem be, that because of the update to Xcode, it actually isn't the same simulator any more (even though they are both iPad 10.5s)?

Core Data loses database file after Xcode upgrade
 
 
Q