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 you handle swift reserved words in the JSON? #86

Closed
dougbeal opened this issue Mar 13, 2015 · 2 comments
Closed

How do you handle swift reserved words in the JSON? #86

dougbeal opened this issue Mar 13, 2015 · 2 comments

Comments

@dougbeal
Copy link

For Example, what if I have this:

"thumbnails": {
     "default": {
      "url": "a"
     },
     "medium": {
      "url": "b"
     },
     "high": {
      "url": "c"
     }
    },

I can't define a struct with a property of default.

@tonyd256
Copy link
Contributor

The key in the JSON is detatched from what you name your property on your model. You can name your property defaultURL and then use "default" when decoding:

struct Thumbnail {
  let defaultURL: NSURL
  ...
}

statuc func decode(j: JSONValue) -> Thumbnail? {
  return Thumbnail.create
    <^> j <| "default"
    <*> ...

@tonyd256
Copy link
Contributor

Closing for now but continue the convo if you're still having trouble.

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