Swift storing an Integer and displaying the changed Integer when reopening the app

40 Views Asked by At

I have an app where when I click a button it increases the value of an Int. When I close the app and then open it again, I want the value of the Int to be whatever it was before closing it. This is in Swiftui and I have multiple Int values that I want to store and reload after closing and opening the app. I dont want where the user clicks a save button to save the Int value, but rather it saves automatically.

I tried AppStorage, but this slowed down the app way too much.

1

There are 1 best solutions below

2
Leith Majdoub On

If it's not too much data you can use UserDefaults.