How to test PublishSubject in RxSwift

Issue #218 RxBlocking does not work with Variable and PublishSubject, see https://github.com/ReactiveX/RxSwift/blob/0b66f666ba6955a51cba1ad530311b030fa4db9c/Tests/RxSwiftTests/Observable%2BSubscriptionTest.swift#L165 Use homemade Recorder class Recorder<T> { var items = [T]() let bag = DisposeBag() func on(arraySubject: PublishSubject<[T]>) { arraySubject.subscribe(onNext: { value in self.items = value }).disposed(by: bag) } func on(valueSubject: PublishSubject<T>) { valueSubject.subscribe(onNext: { value in self.items.append(value) }).disposed(by: bag) } } Then test final class BookViewModelTests: XCTestCase { func testBooks() throws { let expectation = self.expectation(description: #function) let recorder = Recorder<Book>() let viewModel = BookViewModel(bookClient: MockBookClient()) recorder....

April 29, 2019 · 1 min · Khoa Pham

How to map from Swift 5 Resul to RxSwift PublishSubject

Issue #214 extension Result { func to(subject: PublishSubject<Success>) { switch self { case .success(let value): subject.onNext(value) case .failure(let error): subject.onError(error) } } } ...

April 26, 2019 · 1 min · Khoa Pham

A taste of MVVM and Reactive paradigm

Issue #120 Original post https://medium.com/flawless-app-stories/a-taste-of-mvvm-and-reactive-paradigm-5288a819cca1 A taste of MVVM and Reactive paradigm I like Swift, like many other object oriented programming languages. Swift allows you to represent real world objects that have some characteristics and can perform some action. I tend to think of an app as a world where each object is a person. They work and communicate. If a person can’t do the work alone, he needs to ask for help....

December 7, 2017 · 15 min · Khoa Pham