We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have a need to output an empty element, such as the PhoneNumbers element in this example:
<Person> <FirstName><![CDATA[BART]]></FirstName> <LastName><![CDATA[SIMPHSON]]></LastName> <Address1><![CDATA[122 ELMARCH AVE, CYNTHIANA, KY, 41031]]></Address1> <City><![CDATA[CYNTHIANA]]></City> <Zip><![CDATA[41031]]></Zip> <BirthDate><![CDATA[1950-05-01]]></BirthDate> <PhoneNumbers /> </Person>
Here is the struct:
struct Person: Encodable { let FirstName: String //. . . let PhoneNumbers: ???? //what goes here? //. . . } struct PhoneNumber: Encodable { let type: Int let number: String }
I have tried the following values, but none appear in the encoded XML at all:
let PhoneNumbers: [PhoneNumber] = []() let PhoneNumbers: [PhoneNumber]? = nil
I want the encoded XML to include the PhoneNumber element even when empty. Is that possible? If so, how?
Thanks!
The text was updated successfully, but these errors were encountered:
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.
PhoneNumbers
PhoneNumber
Does that resolve your issue?
Sorry, something went wrong.
That was the key. Problem solved. Thanks Max. Nice utility.
ksoftllc
No branches or pull requests
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!
The text was updated successfully, but these errors were encountered: