TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Antoine v.d. Lee.
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 | Pod version |
---|---|
3.X | >= 2.0.0 |
2.3 | 1.0.0 |
To run the example project, clone the repo, and run pod install
from the Example directory first. It includes sample code and unit tests.
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]
}
}
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)
}
}
RCStubbedProvider.request(token: ExampleAPI.getObject)
.map(to: GetResponse.self)
.on(failed: { (error) -> () in
print(error)
}) { (response) -> () in
print(response)
}.start()
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)
If you're using SwiftyJSON, checkout Moya-SwiftyJSONMapper
Antoine van der Lee
Mail: [email protected]
Home: www.avanderlee.com
Twitter: @twannl
Moya-JASONMapper is available under the MIT license. See the LICENSE file for more info.