in

When ever I press certain button the app crashes and gives me this Error "Unexpectedly found nil while unwrapping an Optional value" how do i fix it?


//This is the code

import UIKit
import AVFoundation

class ViewController: UIViewController {

override func viewDidLoad() {
   super.viewDidLoad()
    // Do any additional setup after loading the view.



}

@IBOutlet weak var titleLabel: UILabel!

@IBOutlet weak var progressBar1: UIProgressView!

       



 let coffeeTimes = ["start": 5]
var timer = Timer()
var player: AVAudioPlayer!
var totalTime = 0
var secondsPassed = 0

@IBAction func startButtonPressed(_ sender: UIButton) {

//when I press the start button it crashes and gives me the Error

    let startB = sender.titleLabel?.text
    totalTime = coffeeTimes[startB!]! //This the line of code that is giving me the Error
   
    
    
    progressBar1.progress = 0.0
    secondsPassed = 0
    titleLabel.text = "coffee timer"
    
    timer = Timer.scheduledTimer(timeInterval: 1.0, target:self, selector: #selector(updateTimer), userInfo:nil, repeats: true)
}

@objc func updateTimer() {
    if secondsPassed < totalTime {
        secondsPassed += 1
        progressBar1.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: "mp3")
        player = try! AVAudioPlayer(contentsOf: url!)
        player.play()
    }
}

}



Source: https://stackoverflow.com/questions/70552548/when-ever-i-press-certain-button-the-app-crashes-and-gives-me-this-error-unexpe

Function not loading data into C++ vector (XCODE)

Implements a deep pretty printer for Go data structures to aid in debugging