0

I don't know if this question has already been asked partly because I don't know how to formulate it... That's why I create this question with a concrete example to make it clear.

I have a guard statement like this:

guard let id = place["place_id"].string,
      let name = place["name"].string,
      let lat = place["geometry"]["location"]["lat"].double,
      let long = place["geometry"]["location"]["lng"].double

}

This statement allows me to handle missing datas in a JSON. However, I have much more data to check compared to this example. Therefore, is there a way to find out which one of these data is missing? I mean, can I use the guard statement to output the missing data in my console ?

Hope it's clear. Thanks in advance for your help.

Paul Bénéteau
  • 775
  • 2
  • 12
  • 36
  • 1
    Decode the JSON with `Decodable` in Swift 4. The decoder tells you exactly what's wrong and where. – vadian Apr 28 '18 at 16:46

1 Answers1

0

You could do it like so:

guard let id = place["place_id"].string else { 
    print("place_id is nil")
 }
guard let name = place["name"].string else {
    print("name is nil")
}
...
Martin Muldoon
  • 3,388
  • 4
  • 24
  • 55