I know that there are similar questions around, but I could not find a single specific problem. I have a request where I want to check for a key error. it is not there, everything is in order, if not, I have to handle the error. Currently, I have implemented it as follows:
if let error = json["error"] {
}
else {
}
I would like to use the guard instruction here so that the success case is not indexed. The only way I came up with is
guard json["error"] == nil else {
let error = json["error"]!
}
but that seems wrong to me with !. Are there any other approaches to this?
warly source
share