Skip to content

heoblitz/RxAssign

Repository files navigation

RxAssign

Support Combine Assign subscriber in RxSwift.

Assign uses a KeyPath which is really nice and useful.

** RxAssign extends Driver and Signal in RxCocoa.

At a Glance

Assign element with key path.

Driver.of("hello")
    .assign(to: \.title, on: test)
    .disposed(by: disposeBag)
Signal.of("world")
    .assign(to: \.test.title, on: self)
    .disposed(by: disposeBag)

These equivalent to assign

  1. Subscribe using emit(or drive) and assign.
class Test {
    var title: String = ""
}

Signal.of("hello")
    .emit { (title: String) in
        test.title = title
    }
    .disposed(by: disposeBag)
  1. Adopt ObserverType in Object and emit(or drive).
class Test: ObserverType {
    typealias Element = String
    
    var title: String = ""
    
    func on(_ event: Event<String>) {
        if case let .next(element) = event {
            title = element
        }
    }
}

Driver.of("world")
    .drive(test)
    .disposed(by: disposeBag)

Dependencies

RxSwift, RxCocoa 6.0+

Installation

Swift Package Manager

Project > Project Dependencies > Add   https://github.com/heoblitz/RxAssign

Cocoapods

pod 'RxAssign'

License

MIT