Hello friends , I am working on a golf app and a feature is a stroke counter for each hole.
This is the code for adding and removing strokes, however every time I change the view controller, the number resets.
Could anyone point me in the right direction regarding somehow storing the number? Thanks!
- Matej
—Code—
import UIKit class Hole2: UIViewController { @IBOutlet weak var StrokeCounter2: UILabel! @IBAction func plus2() { guard let presentValue2 = Int(StrokeCounter2!.text!), presentValue2 < 9 else { return } let newValue2 = presentValue2 + 1 StrokeCounter2!.text = String(newValue2) } @IBAction func minus2() { guard let presentValue2 = Int(StrokeCounter2!.text!), presentValue2 > 0 else { return } let newValue2 = presentValue2 - 1 StrokeCounter2!.text = String(newValue2) } override func viewDidLoad() { super.viewDidLoad() } }