Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The process has been returned to the state before expression evaluation. (lldb) [duplicate]

Tags:

ios

swift

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

like image 816
Ahmad Avatar asked Jul 10 '17 05:07

Ahmad


2 Answers

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
     }                     
})
like image 175
Yun CHEN Avatar answered Sep 26 '22 06:09

Yun CHEN


Read about type casting.

Verify that type of the parseJSON["message"] is String before.

if let message = parseJSON["message"] as? String {

}
like image 35
Oleg Gordiichuk Avatar answered Sep 22 '22 06:09

Oleg Gordiichuk