Chapter 7: The New Look

func startNewRound() {
    round += 1
    targetValue = Int.random(in: 1...100)
    
    currentValue = 50
    slider.value = Float(currentValue)
    updateLabels()
}

I got Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value that point to slider in slider.value = Float(currentValue)

I have checked that I have connected @IBOutlet weak var slider: UISlider! to the slider in storyboard

then I try to change to slider?.value = Float(currentValue) and every other line that use slider then it stop throwing error. can anyone tell why? the book don’t use optional chaining but it can work without error

Optional chaining only hides the issue - it does not fix it. Generally, the error would seem to indicate that the outlet is connected but since you indicate that you checked, that should not be the issue.

The easiest way to know is to check the project itself. Please upload your project as a ZIP file somewhere and provide a link to the ZIP file so that I (or someone else) can download the file and see what might be going on.

I got the error everytime I click info button. this is a ZIP file for my project

I am not getting a crash in sartNewRound at all when I run the code. Two possibilities:

  1. Your project data has some issue on your device. Try cleaning the project (via Product - Clean Build Folder menu option) and try running again.

  2. You have sent me the wrong version of the code. You might be running/building one version but sent me the code from a different location?

Try option #1 first and that doesn’t work, verify that you sent me the correct code. If the code is correct, try extracting the ZIP file you sent me to a different location, run that project and see if that one crashes too.