Files
swift-mirror/test/refactoring/AddCodableImplementation/Outputs/extension/conditional.swift.expected
Rintaro Ishizaki 39606e6269 [refactoring] Rework "add codable implementation" refactoring
* Support extensions including conditional conformance
* Correct access modifiers
* More correct lookup for the synthesized declarations
* Avoid printing decls in nested types (rdar://98025945)
2024-03-13 13:34:32 +09:00

49 lines
874 B
Plaintext

struct User {
let firstName: String
let lastName: String?
}
extension User: Codable {
}
struct Generic<Value> {
var value: Value
}
extension Generic {
}
extension Generic: Codable where Value: Codable {
private enum CodingKeys: CodingKey {
case value
}
init(from decoder: any Decoder) throws {
let container: KeyedDecodingContainer<Generic<Value>.CodingKeys> = try decoder.container(keyedBy: Generic<Value>.CodingKeys.self)
self.value = try container.decode(Value.self, forKey: Generic<Value>.CodingKeys.value)
}
func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: Generic<Value>.CodingKeys.self)
try container.encode(self.value, forKey: Generic.CodingKeys.value)
}
}
struct Outer {
struct Inner {
let value: Int
}
}
extension Outer.Inner: Codable {
}