fatal error: unexpectedly found nil while unwrapping an Optional value

Asked

Viewed 1,102 times

-1

I know the problem is simple. but I can’t seem to solve it my variable Beats only appears in the second view, but a function ends up calling it in the first view, I just need to check if she’s showing up, but I’m not getting to do the control if

@IBOutlet weak var Batimentos: UILabel!


if let actualBpm = bpm{
            print(actualBpm)

            Batimentos.text! = "\(actualBpm)"

        }else {
            print("ELSE bpm")
        }
  • If you are assigning a value to the label "Beats", there is no need to force unwrap. Maybe that’s the problem, because possibly at the time of attribution the text is nil and you’re forcing...

2 answers

-1

Try it that way.

@IBOutlet weak var Batimentos: UILabel!


if let actualBpm = bpm{
    print(actualBpm)

    Batimentos.text! = "\(actualBpm!)"

}else {
    print("ELSE bpm")
}

-1

The force unwrap in the text attribute is unnecessary as you are assigning a value. Try so, removing the unwrap force:

@IBOutlet weak var batimentos: UILabel!

if let actualBpm = bpm{
  print(actualBpm)
  batimentos.text = "\(actualBpm)"
} else {
  print("ELSE bpm")
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.