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)
45 lines
933 B
Plaintext
45 lines
933 B
Plaintext
|
|
struct User1: Codable {
|
|
let firstName: String
|
|
let lastName: String?
|
|
|
|
init(from decoder: any Decoder) throws {
|
|
firstName = ""
|
|
lastName = ""
|
|
}
|
|
func encode(to encoder: any Encoder) throws {}
|
|
}
|
|
|
|
|
|
struct User2: Codable {
|
|
let firstName: String
|
|
let lastName: String?
|
|
|
|
init(from decoder: any Decoder) throws {
|
|
firstName = ""
|
|
lastName = ""
|
|
}
|
|
}
|
|
|
|
|
|
struct User3: Codable {
|
|
let firstName: String
|
|
let lastName: String?
|
|
|
|
func encode(to encoder: any Encoder) throws {}
|
|
|
|
private enum CodingKeys: CodingKey {
|
|
case firstName
|
|
case lastName
|
|
}
|
|
|
|
init(from decoder: any Decoder) throws {
|
|
let container: KeyedDecodingContainer<User3.CodingKeys> = try decoder.container(keyedBy: User3.CodingKeys.self)
|
|
|
|
self.firstName = try container.decode(String.self, forKey: User3.CodingKeys.firstName)
|
|
self.lastName = try container.decodeIfPresent(String.self, forKey: User3.CodingKeys.lastName)
|
|
|
|
}
|
|
}
|
|
|