After updating local Xcode to 10.2.0 (and later 10.2.1) I've noticed a change in how raw dictionary keys are returned from JSONDecoder. The decoder's keyDecodingStrategy used to apply to the string keys, and seems to no longer apply. A trivial script that demonstrates this:
import Foundation
#if swift(>=5.0)
print("This is Swift 5.0")
#elseif swift(>=4.2)
print("This is Swift 4.2")
#endif
struct Example: Decodable {
var map: [String: String]
}
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
let input = """
{"map": {"foo_bar_baz": "ning"}}
"""
let data = Data(input.utf8)
let decoded = try! decoder.decode(Example.self, from: data)
print(decoded.map.keys.first!)
And the output with local xcode is:
$ /Applications/Xcode10.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -swift-version 4.2 decode.swift
This is Swift 4.2
fooBarBaz
$ /Applications/Xcode10.2.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -swift-version 4.2 decode.swift
This is Swift 4.2
foo_bar_baz
I've found a previous conversation / pull request starting at
that discusses this change, but it's supposed to be in Swift 5 - what I'm seeing is that swift compiled with Xcode 4.2 exhibits the change as well.
Personally I like this change, but it's pretty backwards incompatible and I don't think Swift 4.2 should change behavior like this based on the tools used to compile it?