Here is all of my code, as said in the title there is an Error occurring when I try to run my app I'm not sure what I can do to fix it. How can I fix this I have tried a couple of things that have not worked.
import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBOutlet weak var progressBar: UIProgressView!
@IBOutlet weak var titleLabel: UILabel!
let coffeeTimes = ["Decaf": 5]
var timer = Timer()
var player: AVAudioPlayer!
var totalTime = 0
var secondsPassed = 0
@IBAction func coffeeSelected(_ sender: UIButton) {
timer.invalidate()
let coffee = sender.currentTitle!
totalTime = coffeeTimes[coffee]!
progressBar.progress = 0.0
secondsPassed = 0
titleLabel.text = coffee
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 = "check coffee"
let url = Bundle.main.url(forResource: "alarm_sound", withExtension: "mixkit-warnin...uzzer-991(1)")
player = try! AVAudioPlayer(contentsOf: url!)
player.play()
}
}
}