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

How do subtables work? #9

Closed
publicarray opened this issue Jul 21, 2019 · 2 comments
Closed

How do subtables work? #9

publicarray opened this issue Jul 21, 2019 · 2 comments

Comments

@publicarray
Copy link

       let toml = """
[players]
  [players.'tom']
  id = '33968bc5c8a95'
  health = 80
  joinDate = 2019-03-10 17:40:00-07:00
  [players.'steve']
  id = '33968bc5c8a95'
  health = 80
  joinDate = 2019-03-10 17:40:00-07:00
"""

        struct Team: Codable {
            struct Player: Codable {
                let id: String
                let health: Int
                let joinDate: Date
            }

            let players: [Player]
        }

        let team = try! TOMLDecoder().decode(Team.self, from: toml)
        print(team)
Fatal error: 'try!' expression unexpectedly raised an error: Swift.DecodingError.valueNotFound(Swift.UnkeyedDecodingContainer, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "players", intValue: nil)], debugDescription: "Cannot get unkeyed decoding container -- found null value instead."
@publicarray publicarray changed the title How do complicated tables work? How do subtables work? Jul 21, 2019
@publicarray
Copy link
Author

ping @dduan

@dduan
Copy link
Owner

dduan commented Aug 7, 2019

Hi, when you write in TOML

[players]
  [players.'tom']
  id = '33968bc5c8a95'

it's equivalent to JSON

{ "players": { "tom": { "id": "33968bc5c8a95" }}

So that's a mismatch with your struct.

@dduan dduan closed this as completed Aug 7, 2019
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

2 participants