TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by JARM.
To run the example project, clone the repo, and run pod install
from the Example directory first.
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'
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")
}
}
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)")
}
}
}
provider
.request(.AllUsers)
.mapArray(MarshalUser.self)
.observeOn(MainScheduler.instance)
.subscribeNext { users in
self.users = users
self.tableView.reloadData()
}.addDisposableTo(disposeBag)
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
}
}
Feedback, issues or pull requests are welcomed!
This project tries to follow the Moya-ObjectMapper project standards.
JARMourato, [email protected]
Moya-Marshal is available under the MIT license. See the LICENSE file for more info.