-1

From this line of code: lblQuestion.text = currentQuestion!.question

i am getting this error message -
Fatal error: Unexpectedly found nil while unwrapping an Optional value

i am creating a multiple choice quiz and i am very new to swift so any help would be great.

1 Answers1

0

You are explicitly unwrapping the optional variable currentQuestion. When this variable is nil it will cause a crash.

Please read the Swift documentation about optional chaining: https://docs.swift.org/swift-book/LanguageGuide/OptionalChaining.html

You should safely set the text of your label as such:

lblQuestion.text = currentQuestion?.question
Broco
  • 669
  • 4
  • 15