Can someone explain to me why this code here returns the error: "fatal error: unexpectedly found nil while unwrapping an Optional value"
if let steps = legs[0]["steps"] {
for i in 0...steps.length {
print(steps[i])
}
}
while this code:
let steps = legs[0]["steps"]!
print(steps[0])
returns the desired output? I am very confused as I have not been able to get all the values of steps contained in an array somehow..
Similarly:
for i in 0...legs[0]["steps"]!.length {
print(legs[0]["steps"]![i]["start_location"])
}
gets fatal error while:
print(legs[0]["steps"]![0]["start_location"])
returns an optional value
legsand any subtypes that that refers to.count, notlength.