import UIKit import AVFoundation
class ViewController: UIViewController {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var progressBar: UIProgressView!
let eggTimes = ["Soft": 300, "Medium": 420, "Hard": 720]
var timer = Timer()
var totalTime = 0
var secondsPassed = 0
var player: AVAudioPlayer!
@IBAction func hardnessSelected(_ sender: UIButton) {
timer.invalidate()
let hardness = sender.currentTitle!
totalTime = eggTimes[hardness]!
progressBar.progress = 0.0
secondsPassed = 0
titleLabel.text = hardness
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
}
@objc func updateTimer() {
if secondsPassed < totalTime {
secondsPassed += 1
progressBar.progress = Float(secondsPassed) / Float(totalTime)
print(Float(secondsPassed) / Float(totalTime))
} else {
timer.invalidate()
titleLabel.text = "Eggs are ready!"
let url = Bundle.main.url(forResource: "iphone_x_ringtone", withExtension: "mp3")
player = try! AVAudioPlayer(contentsOf: url!)
player.play()
}
}
// Здесь мои мысли ... Кто-нибудь, пожалуйста, сообщите, если вы получаете то, что я пытаюсь делать
@ IBAction fun c resetButtonPressed (_ отправитель: UIButton) {timer.invalidate ()
func viewDidLoad() {
super.viewDidLoad()
}
}}