I found that XCode compiled successfully without codable, but compiled failed using codable.
Compile successfully:
func test() {
let value = Foo()
print("test: \(value)")
// // Using codable cause compilation error;
// if let data = try? JSONEncoder().encode(value),
// let json = String.init(data: data, encoding: .utf8) {
// print(json)
// }
}
Compile failed:
func test() {
let value = Foo()
print("test: \(value)")
// Using codable cause compilation error;
if let data = try? JSONEncoder().encode(value),
let json = String.init(data: data, encoding: .utf8) {
print(json)
}
}
Is it because property wrappers with codable generates codable code after compilation, but the JSONEncoder need the "Foo" struct conforms to codable protocol before compilation.
Everything in one file is OK. I have filed a bug for XCode in https://feedbackassistant.apple.com/. I don't know it is a bug for XCode team or Swift team.