I am trying to save an integer variable in swift/xcode so that when the user opens the application, the number they are incrementing stays the sames (is saved). So far, no luck with this code. The number always goes back to zero when I relaunch the app. The button below simply increments the smoke variable by 1, I want to save that data.
Thank you for your time.
let defaults = UserDefaults.standard
var smoke = 0
@IBAction func incrementSmoke(_ sender: UIButton) {
smoke+=1
defaults.set(smoke, forKey: "smoke")
numDaysLabel.text = String(defaults.integer(forKey: "smoke"))
}
smoke = defaults.integer(forKey: "smoke")in the init method.