Created
November 6, 2015 19:00
-
-
Save pcantrell/1825e30085d6ee03faaa to your computer and use it in GitHub Desktop.
Siesta SwiftyJSON integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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