Thursday, April 30, 2026
HomeiOS Developmentios - Each time i attempt to run my app and press...

ios – Each time i attempt to run my app and press a button the app crashes and offers me this Error, “Unexpectedly discovered nil whereas unwrapping an Non-compulsory worth”

[ad_1]

that is the code and it is giving me an Error.
let espresso = sender.currentTitle!
thats my drawback Im attempting to make my button be the title of the button which is Decaf however when i press it it provides me that Error.

import UIKit
import AVFoundation

class ViewController: UIViewController {

override func viewDidLoad() {
   tremendous.viewDidLoad()
    // Do any extra setup after loading the view.

}

@IBOutlet weak var progressBar: UIProgressView!
   
@IBOutlet weak var titleLabel: UILabel!

let coffeeTimes = ["Decaf": 5, "coffee": 5]
var timer = Timer()
var participant: AVAudioPlayer!
var totalTime = 0
var secondsPassed = 0

@IBAction func coffeeSelected(_ sender: UIButton) {
   
    timer.invalidate()
    let espresso = sender.currentTitle! 1.That is the road have been its giving me the Error"
    totalTime = coffeeTimes[coffee]!
    
    progressBar.progress = 0.0
    secondsPassed = 0
    titleLabel.textual content = espresso



    timer = Timer.scheduledTimer(timeInterval: 1.0, goal: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.textual content = "examine espresso"
        
        let url = Bundle.predominant.url(forResource: "alarm_sound", withExtension: "mp3")
        participant = attempt! AVAudioPlayer(contentsOf: url!)
        participant.play()
    }
}

}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments