Latest 1.3.1
Homepage https://github.com/JARMourato/Moya-Marshal
License MIT
Platforms osx 10.10, ios 8.0, tvos 9.0, watchos 2.0
Authors

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.

Latest podspec

{
    "name": "Moya-Marshal",
    "version": "1.3.1",
    "summary": "Marshal mappings for Moya network requests",
    "description": "[Marshal](https://github.com/utahiosmac/Marshal) bindings forn[Moya](https://github.com/Moya/Moya) for easier JSON serialization.nIncludes [RxSwift](https://github.com/ReactiveX/RxSwift/) andn[ReactiveCocoa](https://github.com/ReactiveCocoa/ReactiveCocoa/) bindings as well.nInstructions on how to use it are inn[the README](https://github.com/JARMourato/Moya-Marshal).",
    "homepage": "https://github.com/JARMourato/Moya-Marshal",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "JARMourato": "[email protected]"
    },
    "source": {
        "git": "https://github.com/JARMourato/Moya-Marshal.git",
        "tag": "1.3.1"
    },
    "social_media_url": "https://twitter.com/_JARMourato",
    "platforms": {
        "osx": "10.10",
        "ios": "8.0",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "default_subspecs": "Core",
    "pushed_with_swift_version": "3.0",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "Sources/*.swift",
            "dependencies": {
                "Moya": [
                    "~> 10.0.0"
                ],
                "Marshal": [
                    "~> 1.2.0"
                ]
            },
            "frameworks": "Foundation"
        },
        {
            "name": "RxSwift",
            "source_files": "Sources/RxSwift/*.swift",
            "dependencies": {
                "Moya/RxSwift": [],
                "Moya-Marshal/Core": [],
                "RxSwift": [
                    "~> 4.0.0"
                ]
            }
        },
        {
            "name": "ReactiveSwift",
            "source_files": "Sources/ReactiveSwift/*.swift",
            "dependencies": {
                "Moya/ReactiveSwift": [],
                "Moya-Marshal/Core": [],
                "ReactiveSwift": []
            }
        }
    ]
}

Pin It on Pinterest

Share This