How to test PublishSubject in RxSwift

Issue #218 RxBlocking does not work with Variable and PublishSubject, see 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 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鈥檛 do the work alone, he needs to ask for help....

December 7, 2017 路 15 min 路 Khoa Pham