Last active
February 23, 2021 23:08
-
-
Save meyusufdemirci/71ef823d20bd5ec41f049621c5e5f9a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 RxCocoa | |
| import RxSwift | |
| class ListViewModel { | |
| // MARK: Properties | |
| let coins: BehaviorRelay<[Coin]> = .init(value: []) | |
| func refreshCoins() { | |
| coins.accept(getDummyCoins()) | |
| } | |
| func search(_ text: String?) { | |
| if let text = text, !text.isEmpty { | |
| coins.accept(getDummyCoins().filter { $0.symbol.lowercased().contains(text.lowercased()) }) | |
| } else { | |
| coins.accept(getDummyCoins()) | |
| } | |
| } | |
| } | |
| private extension ListViewModel { | |
| func getDummyCoins() -> [Coin] { | |
| [ | |
| .init(symbol: "BTCUSDT", price: 42500), | |
| .init(symbol: "ETHUSDT", price: 1500), | |
| .init(symbol: "XRPUSDT", price: 0.5), | |
| .init(symbol: "LTCUSDT", price: 175) | |
| ] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment