Мне нужен способ изменить мой код, чтобы убрать ошибки и сделать так, чтобы он начинал обратный отсчет в зависимости от того, какое яйцо было нажато: мягкое яйцо, таймер обратного отсчета 300 секунд; среднее яйцо, 420 секунд; твёрдое яйцо, 720 секунд
import UIKit
class ViewController: UIViewController {
let eggTimes = ["Soft": 300, "Medium": 420, "Hard": 720]
@IBAction func hardnessSelected(_ sender: UIButton) {
let hardness = sender.currentTitle!
var counter = eggTimes[hardness]!
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateCounter), userInfo: nil, repeats: true)
@objc func updateCounter() {
if counter > 0 {
print("\(counter) seconds to the end of the world")
counter -= 1
}
}
}
}