Skip to content

Instantly share code, notes, and snippets.

@meyusufdemirci
Last active February 21, 2021 17:22
Show Gist options
  • Select an option

  • Save meyusufdemirci/30718d1df601d5dd5f9a51f3dba3ed73 to your computer and use it in GitHub Desktop.

Select an option

Save meyusufdemirci/30718d1df601d5dd5f9a51f3dba3ed73 to your computer and use it in GitHub Desktop.
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