I want the code to start a var num = 0. Then after every button hit num increases by 1. The problem that I am running into is that when I switch view controllers and come back to this one it starts at 0 again. Num can only starts at 0 one tie when is loaded for the first time. I want to use userdefults to save the number so no matter what the score will always increase.
import UIKit
class ViewController: UIViewController {
var num = 0
let defaults = UserDefaults.standard
@IBAction func press () {
num += 1
defaults.set(num, forKey: "num")
}
}