0

Every time I try to set the value of a UILabel.text in swift it spits out the error "Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value". I am trying to set it to a value in a Double array plus a string.

Here is the code

I have tried to manually set the values of the variables i have also tried to set the value of the normal variable but nothing has fixed it.

let normal = [10, 0, 0.105, 0.002, 0, 0, 0, 0.020, 0.00375, 0.00000192, 0.0025]
let cal = normal[0] * 1
    let fat = normal[1] * 1
    let sod = normal[2] * 1000
    let car = normal[3] * 1000
    let sug = normal[4] * 1
    let pro = normal[5] * 1
    let cac = normal[6] * 1000
    let nia = normal[7] * 100
    let vb6 = normal[8] * 1000
    let b12 = normal[9] * 1000000
    let pan = normal[10] * 1000
let caf = Double(80)
//print(caf)
cal84.text = "Calories: \(cal)"
fat84.text = "Fat: \(fat)"
sod84.text = "Sodium: \(sod)"
car84.text = "Total Carbohydrates: \(car)"
sug84.text = "Total Sugar: \(sug)"
pro84.text = "Protein: \(pro)"
calc84.text = "Calcium: \(cac)"
nia84.text = "Niacin: \(nia)"
vb684.text = "Vitamin B6: \(vb6)"
b1284.text = "Vitamin B12: \(b12)"
pan84.text = "Pantothenic Acid \(pan)"
Riri
  • 1
  • 1
  • 1
    Your Array works ok. If using interface builder, check your outlets are all properly connected. This is common problem, asked many times. Take a look at https://stackoverflow.com/questions/24948302/fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-value – rbaldwin Jul 03 '21 at 18:12
  • Ok I will check when I get back home. – Riri Jul 04 '21 at 21:02

0 Answers0