Git Product home page Git Product logo

moya-marshal's Introduction

Moya-Marshal

CocoaPods Swift 3.0.x

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

CocoaPods

pod 'Moya-Marshal'

The subspec if you want to use the bindings over RxSwift.

pod 'Moya-Marshal/RxSwift'

And the subspec if you want to use the bindings over ReactiveSwift.

pod 'Moya-Marshal/ReactiveSwift'

Usage

Create a Class or Struct which implements the Unmarshaling protocol.

import Foundation
import Marshal

struct User: Unmarshaling {
  var id: Int
  var name: String
  var email: String

  init(object: MarshaledObject) throws {
    id = try object.value(for: "id")
    name = try object.value(for: "name")
    email = try object.value(for: "email")
  }
}

Moya.Response mapping

provider
    .request(.AllUsers) { result in
        if case let .Success(response) = result {
            do {
                let argoUsers:[ArgoUser] = try response.mapArray(MarshalUser.self)
                print("mapped to users: \(argoUsers)")
            } catch {
                print("Error mapping users: \(error)")
            }
        }
    }

RxSwift

provider
    .request(.AllUsers)
    .mapArray(MarshalUser.self)
    .observeOn(MainScheduler.instance)
    .subscribeNext { users in
        self.users = users
        self.tableView.reloadData()
    }.addDisposableTo(disposeBag)

ReactiveSwift

provider
    .request(.AllUsers)
    .mapArray(MarshalUser.self)
    .observeOn(UIScheduler())
    .start { event in
        switch event {
        case .Next(let users):
            self.users = users
            self.tableView.reloadData()
        case .Failed(let error):
            print("error: \(error)")
        default: break
        }
    }

Contributing

Feedback, issues or pull requests are welcomed!

Thanks

This project tries to follow the Moya-ObjectMapper project standards.

Author

JARMourato, [email protected]

License

Moya-Marshal is available under the MIT license. See the LICENSE file for more info.

moya-marshal's People

Contributors

jarmourato avatar xavierlowmiller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

finger-ink

moya-marshal's Issues

Update dependency to Moya 10.0.0

Thanks so much for writing Moya-Marshal!

Now that Moya has released 10.0.0, can you update the dependency in the podspec?

Thanks!

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.