Home > Enterprise >  Create and restore snapshot in Xcode 13 just like Android Studio with Android Emulator
Create and restore snapshot in Xcode 13 just like Android Studio with Android Emulator

Time:02-12

I use Android Studio and Xcode to develop Android and iOS apps respectively.

When I use Android Studio, I can use an option to create a snapshot on android emulator. This way I can restore the snapshot and continue the development using the same data that stored in Sqlite database and SharedPreferences.

I use Xcode and want to replicate the behavior do the same process on the iOS simulator because I want to retain data in UserDefaults and the Sqlite database.

I see some options to do that in a very old version of Xcode, but can't find it in the Xcode 13 version.

Is it possible to create and restore a snapshot on Xcode 13 and iOS Simulator just like in Android Studio with Android Emulator ?

If is not possible, there is any other way or workaround to do something similar ?

CodePudding user response:

I found a workaround since I can't find a way to use snapshot with Xcode and iOS Simulator.

I use the following code in my app:

print("home directory: \(NSHomeDirectory())" )

This code shows where the iOS simulator folder of the app is located

With that information, I can find the database.sqlite file. I can copy and backup the file or edit the info inside direct in the database.sqlite file.

This way I can use the app and restore the database.sqlite when I want to.

After I edit some info in this file, I just need to remember to run the app again using Ctrl R.

The same is valid with the file that contains the UserDefaults data stored by the app. This file is located inside HomeDirectory/Library/Preferences/<app_bundle_id>.plist

You can edit and backup the file if you want, but if you modify the file, remember to run the app again with Xcode.

  • Related