class ViewController: UIViewController {
let eggTimes = ["Soft": 5, "Medium": 7, "Hard" : 12]
@IBOutlet weak var eggCountdown2: UILabel!
@IBOutlet weak var eggCountDown: UILabel!
@IBOutlet weak var eggCountdown3: UILabel!
var count1 = 7
var count2 = 5
var count3 = 12
override func viewDidLoad() {
super.viewDidLoad()
var timer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector: #selector(UIMenuController.update), userInfo: nil, repeats: true)
}
@objc func update() {
switch UILabel() {
case eggCountDown:
print("\(count1) seconds to get your medium egg")
count1 -= 1
case eggCountdown2 :
print("\(count2) seconds to get your soft egg")
count2 -= 1
case eggCountdown3 :
print("\(count3) seconds to get your fucking hard egg")
count3 -= 1
default:
print ("Error")
}
}
@IBAction func hardnessSelected(_ sender: UIButton) {
let hardness = sender.currentTitle!
print(eggTimes [hardness]!)
}
}
I am getting "Error" countdowns in my EggTimer code. It's supposed to be counting down the time each egg takes. I have tried multiple ways to tackle this but always ended with up this. Also I have been scraping Apple documentation for the same but still cannot find the relevant answer.
Screen shot:

Rather than switching on an unrelated label – which cannot work – create a property for the hardness
and one counter is sufficient as you apparently not going to run two timers simultaneously.
and assign both values in
hardnessSelectedThen switch this way
And you need to check when the countdown ends and to start the timer in the
IBAction. And to avoid bad cooking experience set the repeat interval to 60 (one minute) or multiply the egg times by 300.