Marshal bindings for Moya, RxSwift and ReactiveCocoa
Swift Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
Sources
.gitignore
.swift-version
LICENSE
Moya-Marshal.podspec
README.md

README.md

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, joao.armourato@gmail.com

License

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