RxJSON

2.0.0

RxSwift wrapper for JSON
devxoul/RxJSON

What's New

2019-06-14T11:36:55Z
  • Add Swift 5 support 🚀 (#3)

RxJSON

Swift CocoaPods Build Status codecov

RxSwift wrapper for JSON.

At a Glance

This is an example of converting a json dictionary observable to a string observable:

URLSession.shared.rx.json(url: "https://api.github.com/repos/ReactorKit/ReactorKit")
  .mapJSON("owner")              // Observable<Any> -> Observable<Any>
  .mapJSON("login", String.self) // Observable<Any> -> Observable<String>
  .bind(to: ownerNameLabel.rx.text)

mapJSON() supports both JSON dictionary and array:

// Dictionary
Observable<Any>.mapJSON("key")           // Observable<Any>
Observable<Any>.mapJSON("key", Int.self) // Observable<Int>

// Array
Observable<Any>.mapJSON(at: 2)              // Observable<Any>
Observable<Any>.mapJSON(at: 3, String.self) // Observable<String>

mapJSON() will throw a RxJSONError when there's no value for given accessor or fails to cast to a given type:

// Dictionary
source.mapJSON("unknownKey")    // Event.error(RxJSONError.valueNotFound)
source.mapJSON("name", Int.key) // Event.error(RxJSONError.castingFailed)

// Array
source.mapJSON(at: -1)          // Event.error(RxJSONError.valueNotFound)
source.mapJSON(at: 0, Int.key)  // Event.error(RxJSONError.castingFailed)

Installation

Contributing

Any discussions and pull requests are welcomed 💖

To create a Xcode project:

$ swift package generate-xcodeproj

License

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

Description

  • Swift Tools 5.0.0
View More Packages from this Author

Dependencies

Last updated: Thu Apr 11 2024 11:32:54 GMT-0900 (Hawaii-Aleutian Daylight Time)