I believe I have found a bug in the JSONDecoder. If one tries to decode a JSON object with more than 8 properties, I get an unrecognizable error:
error: Execution was interrupted, reason: EXCBADACCESS (code=1,
address=0xe8). The process has been left at the point where it was
interrupted, use "thread return -x" to return to the state before
expression evaluation.
This error happens whenever I execute code similar to below:
struct Objects: Codable {
var NAME1: String?
var NAME2: String?
var NAME3: String?
var NAME4: String?
var NAME5: String?
var NAME6: String?
var NAME7: String?
var NAME8: String?
var NAME9: String?
}
let NEWDATA = """
[
{
"NAME1": "hi",
"NAME2": "hi",
"NAME3": "hi",
"NAME4": "hi",
"NAME5": "hi",
"NAME6": "hi",
"NAME7": "hi",
"NAME8": "hi",
"NAME9": "HELLO"
}
]
""".data(using: .utf8)!
let decoder2 = JSONDecoder()
let product2 = try decoder2.decode([Objects].self, from: NEWDATA)
print(product2)
This happens in both the Playground and on the device. Maybe I am doing something wrong but it works when you have only 8 properties in the Objects struct but not when you have 9 or more.
Xcode Version: 12.1
Swift Version: 5.3
Thanks for all your help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…