Nadia G Nadia G - 6 months ago 50
Swift Question

Showing optional double number on a label

I'm trying to show a double number on a label. But it shows as an optional. I can't unwrap it using "!" because some of the data is nil.

How can I make the "Optional(...)" text not show up?

This is how it looks:

let row = elementArray[indexPath.row]
mPoint.text = String(row.meltPoint) //Optional(2070.0)


use if let to unwraping optinal values

let row = elementArray[indexPath.row]
if let myNumber = row.meltPoint {
    mPoint.text = "\(myNumber)"
} esle {
     mPoint.text = "N/A"