Latest 2.2.0
Homepage https://github.com/AvdLee/Moya-JASONMapper
License MIT
Platforms ios 8.0, tvos 9.0, watchos 2.0, requires ARC
Authors

Version
Build Status
Language
License
Platform
Twitter

Installation

Moya-JASONMapper is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Moya-JASONMapper"

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

pod "Moya-JASONMapper/RxSwift"

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

pod "Moya-JASONMapper/ReactiveCocoa"

Swift version vs Pod version

Swift version Pod version
3.X >= 2.0.0
2.3 1.0.0

Usage

Example project

To run the example project, clone the repo, and run pod install from the Example directory first. It includes sample code and unit tests.

Model definitions

Create a Class or Struct which implements the Mappable protocol.

import Foundation
import Moya_JASONMapper
import JASON

final class GetResponse : ALJSONAble {

    let url:NSURL?
    let origin:String
    let args:[String: String]?

    required init?(jsonData:JSON){
        self.url = jsonData["url"].nsURL
        self.origin = jsonData["origin"].stringValue
        self.args = jsonData["args"].object as? [String : String]
    }

}

1. Without RxSwift or ReactiveCocoa

stubbedProvider.request(ExampleAPI.getObject) { (result) -> () in
    switch result {
    case let .success(response):
        do {
            let getResponseObject = try response.map(to: GetResponse.self)
            print(getResponseObject)
        } catch {
            print(error)
        }
    case let .failure(error):
        print(error)
    }
}

2. With ReactiveCocoa

RCStubbedProvider.request(token: ExampleAPI.getObject)
    .map(to: GetResponse.self)
    .on(failed: { (error) -> () in
        print(error)
    }) { (response) -> () in
        print(response)
    }.start()

3. With RxSwift

let disposeBag = DisposeBag()

RXStubbedProvider.request(ExampleAPI.getObject)
    .map(to: GetResponse.self)
    .subscribe(onNext: { (response) -> Void in
        print(response)
    }, onError: { (error) -> Void in
        print(error)
    }).addDisposableTo(disposeBag)

Other repo’s

If you’re using SwiftyJSON, checkout Moya-SwiftyJSONMapper

Author

Antoine van der Lee

Mail: [email protected]
Home: www.avanderlee.com
Twitter: @twannl

License

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

Latest podspec

{
    "name": "Moya-JASONMapper",
    "version": "2.2.0",
    "summary": "Map objects through JASON in combination with Moya",
    "description": "[JASON](https://github.com/delba/JASON) bindings forn[Moya](https://github.com/Moya/Moya) for easier JSON serialization.nIncludes [RxSwift](https://github.com/ReactiveX/RxSwift/) bindings as well.nInstructions on how to use it are inn[the README](https://github.com/AvdLee/Moya-JASONMapper).",
    "homepage": "https://github.com/AvdLee/Moya-JASONMapper",
    "license": {
        "type": "MIT",
        "file": "License"
    },
    "authors": {
        "Antoine van der Lee": "[email protected]"
    },
    "source": {
        "git": "https://github.com/AvdLee/Moya-JASONMapper.git",
        "tag": "2.2.0"
    },
    "social_media_url": "https://twitter.com/twannl",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "requires_arc": true,
    "default_subspecs": "Core",
    "pushed_with_swift_version": "3.0",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "Source/*.swift",
            "dependencies": {
                "Moya": [
                    "~> 8.0.0"
                ],
                "JASON": []
            },
            "frameworks": "Foundation"
        },
        {
            "name": "RxSwift",
            "source_files": "Source/RxSwift/*.swift",
            "dependencies": {
                "Moya-JASONMapper/Core": [],
                "Moya/RxSwift": [],
                "RxSwift": [
                    "~>3.1.0"
                ]
            }
        },
        {
            "name": "ReactiveSwift",
            "source_files": "Source/ReactiveSwift/*.swift",
            "dependencies": {
                "Moya/ReactiveSwift": [],
                "Moya-JASONMapper/Core": [],
                "ReactiveSwift": []
            }
        }
    ]
}

Pin It on Pinterest

Share This