Skip to content
New issue

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

<element /> issue? #103

Closed
pj4533 opened this issue May 22, 2019 · 1 comment
Closed

<element /> issue? #103

pj4533 opened this issue May 22, 2019 · 1 comment

Comments

@pj4533
Copy link

pj4533 commented May 22, 2019

This might be user error, or might be related to #101 not really sure. I am trying to decode:

<?xml version="1.0" encoding="UTF-8"?>
<compendium>
  <foobar>
    <foo>Foo string value</foo>
    <nested>
      <name>Name</name>
      <text>Bar string value</text>
    </nested>
    <nested>
      <name>Name</name>
      <text>Bar string value</text>
      <text />
      <text>Bar string value</text>
    </nested>
  </foobar>
</compendium>

My structs:

           struct NestedObject : Codable {
                var name : String?
                var text : [String]?
            }
            
            struct Foobar : Codable {
                var foo : String?
                var nested : [NestedObject]?
            }
            
            struct Compendium: Codable  {
                var foobars: [Foobar]
                enum CodingKeys: String, CodingKey {
                    case foobars = "foobar"
                }
            }

The empty text in the last nested object fails to decode. I think cause the String inside the array isn't optional, so when not there, the decoder freaks out? Not sure...any help would be appreciated!

@pj4533
Copy link
Author

pj4533 commented May 22, 2019

Derp.....nevermind! I answered my own question.....just needed to make the array element optional!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant