Giter Club home page Giter Club logo

himotoki's Introduction

Himotoki

Join the chat at https://gitter.im/ikesyo/Himotoki

Circle CI Carthage compatible

Himotoki (紐解き) is a type-safe JSON decoding library purely written in Swift. This library is highly inspired by popular JSON parsing libraries in Swift: Argo and ObjectMapper.

Himotoki has the same meaning of 'decoding' in Japanese.

  • Just do JSON decoding (deserialization) well. JSON encoding (serialization) would not be supported going forward. 😉
  • Much simpler API.
  • Fail-fast conditional model building. This is useful for some structs with non-optional let properties.
  • No external dependencies.

See a simple example from a test code:

struct Group: Decodable {
    let name: String
    let floor: Int
    let optional: [String]?

	// MARK: Decodable

    static func decode(e: Extractor) -> Group? {
        // Initializer as a function
        let create = { Group($0) }

        // Create an arguments list which itself is optional,
        // then use it with `Optional.map()`
        return build(
            e <| "name",
            e <| "floor",
            e <||? "optional"
        ).map(create)
    }
}

func testGroup() {
   var JSON: [String: AnyObject] = [ "name": "Himotoki", "floor": 12 ]

   let g: Group? = decode(JSON)
   XCTAssert(g != nil)
   XCTAssert(g?.name == "Himotoki")
   XCTAssert(g?.floor == 12)
   XCTAssert(g?.optional == nil)

   JSON["name"] = nil
   let f: Group? = decode(JSON)
   XCTAssert(f == nil)
}

Requirements

  • Swift 1.2 (Xcode 6.3 or later)
  • iOS 8.0 or later (by Carthage) / iOS 7 (by coping the source files directly)
  • OS X 10.9 or later

Installation

There are 2 options. If your app support iOS 7, you can only use the latter way.

  • Add github "ikesyo/Himotoki" to your Cartfile.
  • Run carthage update.

Copying the source files directly

  • Add this repository as a git submodule:
$ git submodule add https://github.com/ikesyo/Himotoki.git PATH_TO_SUBMODULE

// or

$ carthage update --use-submodules
  • Then just add references of Himotoki/*.swift to your Xcode project.

License

Himotoki is released under the MIT License.

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.