RxSupport 1.0.0

RxSupport 1.0.0

Maintained by outofcode.



 
Depends on:
RxSwift~> 5.0
RxCocoa~> 5.0
 

RxSupport 1.0.0

  • By
  • outofcoding

RxSupport

CI Status Version License Platform

Installation

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

pod 'RxSupport'

Requirements

  • Swift 4

Example

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

ObservableType.Support

Unwrapping for Observable.Element is optional type

// notNil
let optionalValue1: String? = "not nil"
Observable.just(optionalValue1)
    .notNil()
    .subscribe(weak: self) { (self, value) in
        print("string = \(value)")
    }
.disposed(by: disposeBag)

// or
let optionalValue2: String? = nil
Observable.just(optionalValue2)
    .or("null value")
    .subscribe(weak: self) { (self, value) in
        print("string = \(value)")
    }
.disposed(by: disposeBag)

ObservableType.Weak

weak self make and self is nil not work closure. your type saving. flatMap, flatMapFirst, flatMapLatest, do, map, subscribe

// Before
Observable.just(1)
    .map { [weak self] number -> String? in
        if let self = self {
            return "\(self.text) \(number)"
        } else {
            return nil
        }
    }
    .notNil()
    .subscribe(onNext: { [weak self] value in
        guard let self = self else { return }
        print("\(self.format)\(value)")
    })
    .disposed(by: disposeBag)

// After
Observable.just(2)
    .map(weak: self) { (self, number) -> String in
        "\(self.text) \(number)"
    }
    .subscribe(weak: self) { (self, value) in
        print("\(self.format)\(value)")
    }
    .disposed(by: disposeBag)

Author

outofcoding, [email protected]

License

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