I have an array that's populated from a JSON response from an API server. Sometimes the values for a key in this array are Null
I am trying to take the given value and drop it into the detail text of a table cell for display.
The problem is that when I try to coerce the value into an String I get a crash, which I think is because I'm trying to coerce Null into a string.
What's the right way to do this? ex- my response is below type and I'm trying to fetch that array in self.imageArray variable
response = ["abc.jpg","null","xyzzy.jpg"]
self.imageArray = (self.dataArray.value(forKey: "product_image") as? [String])!
but at second iteration it gets crashed coz second value is null.
compactMap. It can handle nil value. - developer.apple.com/documentation/swift/sequence/…nullor"null"?