Nadia G Nadia G - 1 year ago 91
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)

Answer Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download