Closed ksoftllc closed 4 years ago
Hey @ksoftllc, have you tried something like this?
struct Person: Encodable {
//. . .
let PhoneNumbers: PhoneNumbers
//. . .
}
struct PhoneNumbers: Encodable {
enum CodingKeys: String, CodingKey { case items = "PhoneNumber" }
let items: [PhoneNumber]
}
struct PhoneNumber: Encodable {
let type: Int
let number: String
}
This assumes that elements contained within a non-empty PhoneNumbers
element are called PhoneNumber
, I hope the code can be easily adjusted otherwise.
Does that resolve your issue?
That was the key. Problem solved. Thanks Max. Nice utility.
I have a need to output an empty element, such as the PhoneNumbers element in this example:
Here is the struct:
I have tried the following values, but none appear in the encoded XML at all:
I want the encoded XML to include the PhoneNumber element even when empty. Is that possible? If so, how?
Thanks!