I am trying to convert "status" from below response to Int.
{
"status": "200",
"message": "Token successfully generated.",
"data": {
"token": "abc"
}
}
When I try to convert it shows error like Could not cast the value of type '_SwiftValue' to 'NSNumber'.
Here what i have tried in code.
var status:Int = 0
var dict = dictTemp as! Dictionary<String,AnyObject>
if let value = dict["status"] as? String {
status = value.toInt()!
} else if let value = dict["status"] as? Int {
status = value
}
// let status = dictTemp!.value(forKey: "status") as? String ?? ""
if(status == 200)
{
errorCode = 0
error = false
}
else
{
errorCode = 1
error = true
}
It always goes to else part.
Here I have attached screenshot what I can see in JSON data.
Please help me how I can convert status to Int.