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