-1

I had been running/testing my app in the iPhone 11 simulator. I had made some new tables in sqlite, inserted data into those...etc. And all the editing of data,fetching from database and any other work were all done and tested in the iPhone 11 simulator.

But if I changed the simulator to a different one say iPhone 11 Pro Max(or any other simulator), or installed the app into a physical device, none of the new tables I created are present. But if I change back to the iPhone 11 simulator, I get back all the tables and data.

I tried deleting the old app while running in a different simulator and also tried quiting the simulator and restarting it again. But nothing works..

I still see all the tables in iPhone 11 simulator only and in any other simulator or a physical device, none of the tables I created can be seen.

What should I do in this case so that I can get back all my tables whenever I run in a different simulator or a physical device..?

  • Each simulator is like a different device. So if you don't recreate your database at start, or fetch it from remote server, it will be empty. – Larme Apr 25 '20 at 08:27
  • Ok @Larme..so you're saying I'll have to create the database tables everytime for a new simulator..? – user13032222 Apr 25 '20 at 08:33
  • Yes. It's like having n iPhone. They aren't sharing their database. – Larme Apr 25 '20 at 08:38
  • Ok @Larme...but how can I do that when it comes to a physical device..? How can I create a database in that case..also, when multiple users with multiple devices use the app, what would I do..? – user13032222 Apr 25 '20 at 09:24

1 Answers1

0

IOS create separate local storage files for each device/simulator. If you want to use data across devices you need to save data into cloud(firebase is best as it is free and easy).

If you still want to copy data you can do in this way

  1. Print local database reference where you're storing your data from Iphone 11 simulator
  2. Past data on other iphone's/simulator directory.

This method will only work for simulators. To get data onto real device, you need save database file into files and than you can pick file from files and save into application's local storage.

Zain
  • 153
  • 9
  • Ok @Zain...I wanted the data to display for both simulator and device. Could you maybe suggest as to how I might do that..I mean how I can save database file into files to be picked later..? – user13032222 Apr 25 '20 at 08:32
  • Make and export button, on pressing that button export your database file into files(you will show share sheet, user can select any application to share). [This Link](https://stackoverflow.com/questions/35931946/basic-example-for-sharing-text-or-image-with-uiactivityviewcontroller-in-swift). – Zain Apr 25 '20 at 08:35
  • when the app starts up, you can check to see if the default data is already there, and if it's not go ahead and create (and save it) the next time the app starts, your check will see data and take no further action – Russell Apr 25 '20 at 09:01
  • ok @Russell...would you mind showing in a couple of lines of code as to how I can check it..? I'm not sure how the existence of the data can be checked.. – user13032222 Apr 25 '20 at 09:23