I have this struct to parse values from my api..
struct Deals {
let title: String
let detail: String
init(title : String, detail: String) {
self.title = title
self.detail = detail
}
}
Now I'm parsing the data from Alamofire in this format...
if httpResponse.statusCode == 200 {
if let result = response.result.value as? [String:Any] {
guard let top = orderData["data"] as? [Any] else {
return
}
for value in top {
let aDict = value as? [String : Any]
let title = aDict!["title"] as? String
let detail = aDict!["description"] as? String
let theDeals = Deals(title: title!, detail: detail!)
}
}
}
But some of these values have a nil value from server(for eg.detail is nil from server) and so it is causing a crash. I'm having difficulty using an if let
properly so that the crash can be handled. Hope somebody can help...