프로젝트
GitHub에서 보기
bmoliveira/Moya-ObjectMapper
소개
Moya와 RxSwift용 ObjectMapper 바인딩입니다.
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalMoya-ObjectMapper
ObjectMapper bindings for Moya for easier JSON serialization. Includes RxSwift bindings as well.
Installation
CocoaPods
pod 'Moya-ObjectMapper'
The subspec if you want to use the bindings over RxSwift.
pod 'Moya-ObjectMapper/RxSwift'
The subspec if you want to use the bindings over ReactiveSwift.
pod 'Moya-ObjectMapper/ReactiveSwift'
Usage
Create a Class or Struct which implements the Mappable protocol.
import Foundation
import ObjectMapper
// MARK: Initializer and Properties
struct Repository: Mappable {
var identifier: Int!
var language: String?
var url: String!
// MARK: JSON
init?(map: Map) { }
mutating func mapping(map: Map) {
identifier <- map["id"]
language <- map["language"]
url <- map["url"]
}
}
1. Without RxSwift and ReactiveSwift
GitHubProvider.request(.userRepositories(username), completion: { result in
var success = true
var message = "Unable to fetch from GitHub"
switch result {
case let .success(response):
do {
if let repos = try response.mapArray(Repository) {
self.repos = repos
} else {
success = false
}
} catch {
success = false
}
self.tableView.reloadData()
case let .failure(error):
guard let error = error as? CustomStringConvertible else {
break
}
message = error.description
success = false
}
})
2. With RxSwift
GitHubProvider.request(.userRepositories(username))
.mapArray(Repository.self)
.subscribe { event -> Void in
switch event {
case .next(let repos):
self.repos = repos
case .error(let error):
print(error)
default: break
}
}.addDisposableTo(disposeBag)
2. With ReactiveSwift
GitHubProvider.request(.userRepositories(username))
.mapArray(Repository.self)
.start { event in
switch event {
case .value(let repos):
self.repos = repos
case .failed(let error):
print(error)
default: break
}
}
Contributing
Issues and pull requests are welcome!
Author
Ivan Bruel @ivanbruel
Maintainers
Bruno Oliveira @bmoliveira
License
Moya-ObjectMapper is released under an MIT license. See LICENSE for more information.
관련 프로젝트 살펴보기
불러오는 중…