Getting error while i sign in
DispatchQueue.main.async(execute: {
let message = parseJSON["message"] as! String
appDelegate.infoView(message: message, color: colorSmoothRed)
})
on line let message = parseJson["message"] as! String
Error: Fatal Error: unexpectedly found nil while unwrapping an Optional value
The value of key "message" is nil sometimes, so you need to check it:
DispatchQueue.main.async(execute: {
if let message = parseJSON["message"] as? String {
appDelegate.infoView(message: message, color: colorSmoothRed)
} else {
//do something for no-message case
}
})
Read about type casting.
Verify that type of the parseJSON["message"]
is String before.
if let message = parseJSON["message"] as? String {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With