Skip to content

Chapter 2. Drive.

Dmitriy Shulzhenko edited this page Sep 25, 2020 · 25 revisions

I use “drivers” to define and manipulate state. It can be a shared app component state or a simple view state. Equivalent to ViewModel in well known mvvm.

import RxSwift
import RxCocoa
import RxSwiftExt

protocol SearchDriving {
    var isSwitchHidden: Driver<Bool> { get }
    var isLoading: Driver<Bool> { get }
    var results: Driver<[SearchResultItem]> { get }
    var didSelect: Driver<SearchResultItem> { get }
    
    func search(_ query: String)
    func selectCategory(_ category: SearchResultItemType)
    func select(_ model: SearchResultItem)
}
final class SearchDriver: SearchDriving {
    // ...
}

NextI will show how to bind our ViewController with the Driver.

Clone this wiki locally