mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
* Support extensions including conditional conformance * Correct access modifiers * More correct lookup for the synthesized declarations * Avoid printing decls in nested types (rdar://98025945)
36 lines
944 B
Plaintext
36 lines
944 B
Plaintext
|
|
struct User: Codable {
|
|
let firstName: String
|
|
let lastName: String?
|
|
|
|
private enum CodingKeys: CodingKey {
|
|
case firstName
|
|
case lastName
|
|
}
|
|
|
|
init(from decoder: any Decoder) throws {
|
|
let container: KeyedDecodingContainer<User.CodingKeys> = try decoder.container(keyedBy: User.CodingKeys.self)
|
|
|
|
self.firstName = try container.decode(String.self, forKey: User.CodingKeys.firstName)
|
|
self.lastName = try container.decodeIfPresent(String.self, forKey: User.CodingKeys.lastName)
|
|
|
|
}
|
|
|
|
func encode(to encoder: any Encoder) throws {
|
|
var container = encoder.container(keyedBy: User.CodingKeys.self)
|
|
|
|
try container.encode(self.firstName, forKey: User.CodingKeys.firstName)
|
|
try container.encodeIfPresent(self.lastName, forKey: User.CodingKeys.lastName)
|
|
}
|
|
}
|
|
|
|
struct User_D: Decodable {
|
|
let firstName: String
|
|
let lastName: String?
|
|
}
|
|
|
|
struct User_E: Encodable {
|
|
let firstName: String
|
|
let lastName: String?
|
|
}
|