项目作者: fmo91

项目描述 :
ObjectMapper extensions for RxSwift
高级语言: Swift
项目地址: git://github.com/fmo91/RxObjectMapper.git
创建时间: 2017-01-30T13:32:43Z
项目社区:https://github.com/fmo91/RxObjectMapper

开源协议:MIT License

下载


RxObjectMapper

CI Status
Version
License
Platform

Introduction

RxObjectMapper is a set of extensions over Observable<Element> that transforms an Observable<Any> in Observable<T> or Observable<[T]> where T is Mappable.

mapObject

mapObject transforms Observable<Any> into Observable<T> where T is Mappable.

  1. let url = URL(string: "https://jsonplaceholder.typicode.com/posts/1")!
  2. URLSession.shared
  3. .rx.json(url: url)
  4. .mapObject(type: Post.self)
  5. .subscribe(
  6. onNext: { (post: Post) in
  7. print("Post title => \(post.title)")
  8. },
  9. onError: { _ in
  10. print("Error")
  11. }
  12. )
  13. .addDisposableTo(disposeBag)

mapArray

mapArray transforms Observable<Any> into Observable<[T]> where T is Mappable.

  1. URLSession.shared
  2. .rx.json(url: URL(string: "https://jsonplaceholder.typicode.com/posts")!)
  3. .mapArray(type: Post.self)
  4. .subscribe(
  5. onNext: { (posts: [Post]) in
  6. // ...
  7. },
  8. onError: { _ in
  9. print("Error")
  10. }
  11. )
  12. .addDisposableTo(disposeBag)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

RxObjectMapper relies on:

  • RxSwift 3.0
  • RxCocoa 3.0
  • ObjectMapper 2.2
  • Swift 3, of course.

Installation

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

  1. pod "RxObjectMapper"

Author

fmo91, ortizfernandomartin@gmail.com

License

RxObjectMapper is available under the MIT license. See the LICENSE file for more info.