Last active
February 21, 2021 17:22
-
-
Save meyusufdemirci/30718d1df601d5dd5f9a51f3dba3ed73 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 Foundation | |
| class ListViewModel { | |
| // MARK: Properties | |
| var coins: [Coin] = [] | |
| var coinsDidRefresh: (() -> Void)? | |
| var coinsCouldNotRefresh: (() -> Void)? | |
| func refreshCoins() { | |
| coins = getDummyCoins() | |
| coinsDidRefresh?() | |
| } | |
| func search(_ text: String?) { | |
| if let text = text, !text.isEmpty { | |
| coins = getDummyCoins().filter { $0.symbol.lowercased().contains(text.lowercased()) } | |
| } else { | |
| coins = getDummyCoins() | |
| } | |
| coinsDidRefresh?() | |
| } | |
| } | |
| 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