A collection of extensions of common types for the Argo JSON parser.
In Greek mythology, Argo was the ship on which Jason and the Argonauts sailed from Iolcos to retrieve the Golden Fleece.
Given the following JSON, GoldenFleece lets us directly parse an NSURL
from the profile_picture
and a CLLocation
from the location
using Argo/Runes.
{
"name": "Alex",
"profile_picture": "http://example.com/picture.png",
"location": {
"lat": 48.11,
"lon": 16.55
}
}
import Argo
import Runes
import GoldenFleece
struct User {
let name: String
let profilePictureURL: NSURL
let location: CLLocation
}
extension User: Decodable {
static func create(name: String)(profilePictureURL: NSURL)(location: CLLocation) -> User {
return self(name: name, profilePictureURL: profilePictureURL, location: location)
}
static func decode(j: JSON) -> Decoded<User> {
return User.create
<^> j <| "name"
<*> j <| "profile_picture" // directly decodes String into NSURL
<*> j <| "location" // directly decodes location into CLLocation
}
}
GoldenFleece collects helpful extensions for common types to be directly used with Argo/Runes. Currently only a handful extensions are supported, but pull requests are more than welcome.
Class | Description |
---|---|
CLLocation | Converts a JSON dictionary {"lat": 48.2, "lon": 16.36} to a CLLocation . |
NSURL | Converts a JSON string to NSURL |
Add the following line to your Cartfile.
github "aschuch/GoldenFleece"
Then run carthage update
.
Just drag and drop the three .swift
files in the GoldenFleece
folder into your project.
Open the Xcode project and press ⌘-U
to run the tests.
Alternatively, all tests can be run from the terminal using xctool.
xctool -scheme GoldenFleeceTests -sdk iphonesimulator test
- CocoaPods support
- Create something awesome, make the code better, add some functionality, whatever (this is the hardest part).
- Fork it
- Create new branch to make your changes
- Commit all your changes to your branch
- Submit a pull request
Feel free to get in touch.
- Website: http://schuch.me
- Twitter: @schuchalexander