Hello, I am relatively new to Swift, and I recently encountered an JSON data as following
{
game_id: 123456
move: [1, 2, 12345678, null, { blur: 12345, sgf_downloaded_by: [ ] } ]
move_number: 12
}
I originally decoded this JSON data with
extension rtGameMove {
init(dictionary: [String: Any]) throws {
self = try JSONDecoder().decode(rtGameMove.self, from: JSONSerialization.data(withJSONObject: dictionary))
}
}
struct rtGameMove: Decodable {
var game_id: Int?
var move: [QuantumVal]
var move_number: Int?
}
enum QuantumVal: Decodable {
case int(Int)
private enum Codes: String, CodingKey {
case int
}
public init (from decoder: Decoder) throws {
if let int = try? decoder.singleValueContainer().decode(Int.self) {
let move: Int = try decoder.singleValueContainer().decode(Int.self)
self = .int(int)
return
}
//Only the numerical values are useful for me, and the {blur: 12345, sgf_downloaded_by: [] }] is not important
self = .int(0)
}
}
However, when I attempted to retrieve the numerical values as Int in move, the Xcode said that I could not convert QuantumVal to Int. I wonder how could I retrieve the numerical values in move? Thank you so much!