Code Monkey home page Code Monkey logo

goldenfleece's Introduction

GoldenFleece

Carthage compatible

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.

Usage

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
    }
}

Decodeable Extensions

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

Installation

Carthage

Add the following line to your Cartfile.

github "aschuch/GoldenFleece"

Then run carthage update.

Manually

Just drag and drop the three .swift files in the GoldenFleece folder into your project.

Tests

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

Todo

  • CocoaPods support

Contributing

  • 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

Contact

Feel free to get in touch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.