Skip to content

Instantly share code, notes, and snippets.

@pcantrell
Created November 6, 2015 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcantrell/1825e30085d6ee03faaa to your computer and use it in GitHub Desktop.
Save pcantrell/1825e30085d6ee03faaa to your computer and use it in GitHub Desktop.
Siesta SwiftyJSON integration
extension TypedContentAccessors {
/**
Adds a `.json` convenience property to resources that returns a SwiftyJSON `JSON` wrapper.
If there is no data, then the property returns `JSON([:])`.
Note that by default, Siesta parses data based on content type. This accessor is only a way
of conveniently donwcasting and defaulting the data that Siesta has already parsed. (Parsing
happens off the main thread in a GCD queue, never in response one of these content accessors.)
To produce a custom data type that Siesta doesn’t already know how to parse as a Siesta
resource’s content, you’ll need to add a custom `ResponseTransformer`.
*/
var json: JSON {
return JSON(contentAsType(ifNone: [:] as AnyObject))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment