Skip to content

Repository files navigation

Moya-SwiftyJSONMapper

VersionBuild StatusLanguageLicensePlatformTwitter

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
finalclassGetResponse:ALSwiftyJSONAble{leturl:URL?letorigin:Stringletargs:[String:String]?requiredinit?(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)->()inswitch result {caselet.success(response):do{letgetResponseObject=try response.map(to:GetResponse.self)print(getResponseObject)}catch{print(error)}caselet.failure(error):print(error)}}

2. With ReactiveCocoa

stubbedProvider.reactive.request(token:ExampleAPI.GetObject).map(to:GetResponse.self).on(failed:{(error)->()inprint(error)}){(response)->()inprint(response)}.start()

3. With RxSwift

letdisposeBag=DisposeBag()
stubbedProvider.rx.request(ExampleAPI.GetObject).map(to:GetResponse.self).subscribe(onNext:{(response)->Voidinprint(response)}, onError:{(error)->Voidinprint(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: info@avanderlee.com
Home: www.avanderlee.com
Twitter: @twannl

License

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

About

Map objects through SwiftyJSON in combination with Moya

Resources

Code of conduct

Contributing

Stars

118 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages