I have been away from Swift for the last 12 months but have just come back to an application that was previously working (Swift 4.0) but now seems to be failing and I am not sure why.
My problem relates to the JSONDecoder and trying to decode an array of arrays of strings.
var tryingToDecode: [[String]]
The JSON that I am using has the following format (See table below) for the actual data please use the following link.
The code I am using is (See below) self.requestData is the JSON data I am using, which works when decoding all my other data, it just does not work with [[String]]
func TEST_decodeReceivedJSON() {
let decoder = JSONDecoder()
do {
let array = try decoder.decode(DataStruct.self, from: self.requestData)
print(array)
} catch {
print("Error")
}
}
The struct that I am using for the decode is
struct DataStruct: Codable {
var data: [[String]]
}
This is just test code, but when I compile it I always get thrown to the catch error. I have tried searching online but can't find any relevent examples. The strange thing is that prior to Xcode 10 this worked, it was even accepted in the App Store. I have now been informed by a number of users that something is not working and this is indeed the case, it seems to be related to this particular section where the [[String]] is decoded using DataStruct.
Any help or pointers would be very much appreciated.
[EDIT 001] Added a link to the JSON data, the code below shows a minimal example, I am specifically interested in how I should be accessing the [[String]] -- the array of arrays of strings. I am trying to assertain as this was working before is there something wrong with the way I am trying to decode the JSON (maybe a Swift update/change)or is there maybe a problem with JSONDecoder.
[EDIT 002] The solution was [[String?]] and the problem was indeed in the JSON, you just can't see it in the text blizzard of the raw data, if you look at the table view below you can clearly see that Item 10 is "null" and as a consequence the code required an optional String.