I am having difficulty saving/moving data between two view controllers. Specifically, I have a UIStepper on the second view controller that acts as a setting which changes a variable used on the first view controller. When I come back to the second view controller the stepper has returned to its default value which I set on the storyboard attribute inspector.
I believe that I need to make the UIStepper's default value equal to its new value after it was saved but I do not know how to. I am having the same problem with a segmented control where I want whatever selection is left there to save as a setting on my app.
'''
First View Controller:
var volume: Double = 12
var speed: Double = 10
class ViewController: UIViewController {
@IBAction func switchOver(_ sender: Any) {
guard let destinationVC = storyboard?.instantiateViewController(withIdentifier: "popUpID") as? popUpViewController else {
return
}
present(destinationVC, animated: true, completion: nil)
}
}
Second View Controller:
@IBOutlet weak var volumeLabel: UILabel!
@IBAction func volumeStepper(_ sender: UIStepper) {
volume = sender.value
volumeLabel.text = String(sender.value) + " fl oz"
@IBAction func currentSpeed(_ sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
speed = 10 // takes 10 seconds
case 1:
speed = 300 // takes 5 minutes
case 2:
speed = 1200 // takes 20 minutes
case 3:
speed = 2400 // takes 40 minutes
default:
speed = 10
}
}
@IBAction func closePopUp(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
'''