-
-
Save andreaslydemann/6323959257d07275299ab87d9413f8c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
public struct Person { | |
public var car: BehaviorSubject<String> | |
public init(car: BehaviorSubject<String>) { | |
self.car = car | |
} | |
} | |
let disposeBag = DisposeBag() | |
let persons = PublishSubject<Person>() | |
persons | |
.flatMap { | |
$0.car | |
} | |
.subscribe(onNext: { | |
print($0) | |
}) | |
.disposed(by: disposeBag) | |
let john = Person(car: BehaviorSubject(value: "Toyota Corolla")) | |
persons.onNext(john) | |
let alice = Person(car: BehaviorSubject(value: "Honda Accord")) | |
persons.onNext(alice) | |
john.car.onNext("Ford Model T") | |
// Output: | |
// Toyota Corolla | |
// Honda Accord | |
// Ford Model T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment