0

I am trying to make a simple app using Xcode/swift. I am able to save and retrieve data in core data when using the simulator, however when I tested the app using an actual iPhone device my existing data are missing. i don't know why this is, and what to do about it. I am new in iOS development, thanks in advance.

Cei
  • 1
  • 1
  • Do I understand correctly that you are asking why the records from the simulator's database are missing on the device? – user3581248 Feb 14 '17 at 12:53
  • yes, I was able to use it and access it just fine until I tested it on an iphone. – Cei Feb 14 '17 at 13:06

1 Answers1

0

This is expected behavior, because youк needed data stored in simulator memory on the mac, and you should copy that database file from simulator to Supporting Files in main bundle of your app and then copy to Documents directory of your app in real device. So steps:

  1. find simulator file: Sqlite File Location Core Data
  2. copy this file to Supporting file of your project
  3. copy that file to Documents directory: iOS ship application with pre populated sqlite database
Community
  • 1
  • 1
  • My Library doesn't have a Developer folder and my Application Support folder doesn't contain iPhone Simulator folder – Cei Feb 14 '17 at 13:24
  • you should go to another Library folder, it's hidden by default http://www.redmondpie.com/enable-hidden-library-folder-on-mac-in-macos-sierra-heres-how/ – Vlad Krasovsky Feb 14 '17 at 13:39
  • I was able to find this: /Library/Developer/CoreSimulator/Devices/8E4B7EBF-7D29-4323-AFCB-F0B20D2A11A7/data/Containers/Data/Application/A4AC0A11-3F98-4A90-A865-90BDE01816AA/Documents but the Documents folder is empty. I apologize, I am really new to this. – Cei Feb 14 '17 at 13:42
  • alternatively you can see the location of datastore in debug when you attach it to persistent store coordinator, and also make hidden fines in finder visible (google it) – Vlad Krasovsky Feb 14 '17 at 13:46
  • I was finally found it in Application Support folder. Thank you very much Vlad. :) – Cei Feb 14 '17 at 14:42