I made an app Single Application. I put a button called CountUpButton, a label called CountLabel, and another button ResetButton. The function of CountUpButton is when button is pressed, the CountLabel has to change + 1 and when ResetButton is pressed, CountLabel has to turn to 0. But the problem is that whenever I reboot my iPhone or App, CountLabel turns back to 0. It's supposed CountLabel to be saved, so it have to change only when ResetButton is pressed.
The code of This function is:
var CountNumber = 0
@IBAction func ResetButton(sender: UIButton) {
CountNumber = 0
CountLabel.text = "0"
}
@IBOutlet var CountLabel: UILabel!
@IBAction func CountUpButton(sender: UIButton) {
CountNumber += 1
CountLabel.text = "\(CountNumber)"
}
and code that I used for "CountLabel" to be saved is:
func saveCounted(){
let defeaults = NSUserDefaults.standardUserDefaults()
defeaults.setInteger(CountNumber, forKey: "CountLabel")
}