I am experiencing a strange crash in my app while updating a label.text
with a string from a variable that does have a value.
if WalletViewController.currencyUSD == true {
MainViewController.bitcoinDoublePrice = Double((bitcoinInfo.raw.btc.usd?.price)!)
print("MainViewController.bitcoinDoublePrice =", MainViewController.bitcoinDoublePrice)
let formatter = NumberFormatter()
formatter.numberStyle = .currency
formatter.locale = Locale(identifier: "en_US")
let bitcoinStringPrice = formatter.string(from: NSNumber(value: MainViewController.bitcoinDoublePrice))
print("bitcoinStringPrice =", bitcoinStringPrice!)
if let bitcoinPrice = bitcoinStringPrice {
MainViewController().bitcoinPriceLabel.text = String(bitcoinPrice + ", ") //<<<Thread 3: Fatal error: Unexpectedly found nil while unwrapping an Optional value
} else {
print("bitcoinPrice = nil")
}
}
Some screenshots:
I can't figure out what's going on here