Hi!
After iOS 17 beta release we started getting negative feedback from our users. While researching the issue I found out that the value of codingPath on iOS 17 is different from one on iOS 16.
Example to reproduce this
import Foundation
class DynamicCodingKey: CodingKey {
let stringValue: String
required init?(stringValue: String) {
self.stringValue = stringValue
}
var intValue: Int? { return nil }
required init?(intValue: Int) { return nil }
}
struct Response: Decodable {
enum CodingKeys: String, CodingKey {
case content
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let contentContainerCodingKey = DynamicCodingKey(stringValue: "dynamicValue")
let contentContainer = try container.nestedContainer(keyedBy: DynamicCodingKey.self, forKey: .content)
try contentContainer.decode(Content.self, forKey: contentContainerCodingKey!)
}
}
struct Content: Decodable {
public init(from decoder: Decoder) throws {
print("---> \(decoder.codingPath)")
throw NSError()
}
}
let exampleString = """
{
"content": {
"dynamicValue": {
"keyA": 4,
"keyB": "dynamicValue",
}
}
}
"""
let exampleData = exampleString.data(using: .utf8)!
do {
try JSONDecoder().decode(Response.self, from: exampleData)
} catch {
}
print output for XCode 14 playground or iOS 16:
---> [DynamicCodingKey(stringValue: "dynamicValue", intValue: nil)]
print output for XCode 15 playground or iOS 17:
---> [CodingKeys(stringValue: "content", intValue: nil), DynamicCodingKey(stringValue: "dynamicValue", intValue: nil)]
Could you tell it is expected behaviour since iOS 17 or bug?