Support Combine Assign
subscriber in RxSwift.
Assign
uses a KeyPath which is really nice and useful.
** RxAssign extends Driver and Signal in RxCocoa.
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
- 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)
- 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)
RxSwift, RxCocoa 6.0+
Project > Project Dependencies > Add https://github.com/heoblitz/RxAssign
pod 'RxAssign'
MIT