Latest 3.0.0
Homepage https://github.com/AvdLee/Moya-SwiftyJSONMapper
License MIT
Platforms ios 8.0, tvos 9.0, watchos 3.0, requires ARC
Authors

Version
Build Status
Language
License
Platform
Twitter

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_SwiftyJSONMapper
import SwiftyJSON

final class GetResponse : ALSwiftyJSONAble {

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

    required init?(jsonData:JSON){
        self.url = jsonData["url"].URL
        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

stubbedProvider.reactive.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()
stubbedProvider.rx.request(ExampleAPI.GetObject).map(to: GetResponse.self).subscribe(onNext: { (response) -> Void in
    print(response)
}, onError: { (error) -> Void in
    print(error)
}).addDisposableTo(disposeBag)

Installation

CocoaPods

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

pod "Moya-SwiftyJSONMapper"

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

pod "Moya-SwiftyJSONMapper/RxSwift"

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

pod "Moya-SwiftyJSONMapper/ReactiveCocoa"

Other repo’s

If you’re using JASON for parsing JSON data, checkout Moya-JASONMapper.

If you’re really into reactive programming, checkout ALDataRequestView and handle those edge cases with ease!

Author

Antoine van der Lee

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

License

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

Latest podspec

{
    "name": "Moya-SwiftyJSONMapper",
    "version": "3.0.0",
    "summary": "Map objects through SwiftyJSON in combination with Moya",
    "description": "[SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON) 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-SwiftyJSONMapper).",
    "homepage": "https://github.com/AvdLee/Moya-SwiftyJSONMapper",
    "license": {
        "type": "MIT",
        "file": "License"
    },
    "authors": {
        "Antoine van der Lee": "[email protected]"
    },
    "source": {
        "git": "https://github.com/AvdLee/Moya-SwiftyJSONMapper.git",
        "tag": "3.0.0"
    },
    "social_media_url": "https://twitter.com/twannl",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0",
        "watchos": "3.0"
    },
    "requires_arc": true,
    "default_subspecs": "Core",
    "pushed_with_swift_version": "4.0",
    "subspecs": [
        {
            "name": "Core",
            "source_files": "Source/*.swift",
            "dependencies": {
                "Moya": [
                    "~> 10.0"
                ],
                "SwiftyJSON": []
            },
            "frameworks": "Foundation"
        },
        {
            "name": "RxSwift",
            "source_files": "Source/RxSwift/*.swift",
            "dependencies": {
                "Moya/RxSwift": [],
                "Moya-SwiftyJSONMapper/Core": []
            }
        },
        {
            "name": "ReactiveCocoa",
            "source_files": "Source/ReactiveCocoa/*.swift",
            "dependencies": {
                "Moya/ReactiveSwift": [],
                "Moya-SwiftyJSONMapper/Core": []
            }
        }
    ]
}

Pin It on Pinterest

Share This