Created
January 2, 2020 19:50
-
-
Save azamsharp/86d6385f7dac0c97c0b96ff6ca125eda 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 | |
import SwiftUI | |
class StockListViewModel: ObservableObject { | |
@Published var searchTerm: String = "" | |
@Published var stocks: [StockViewModel] = [StockViewModel]() | |
func load() { | |
fetchStocks() | |
} | |
private func fetchStocks() { | |
Webservice().getStocks { stocks in | |
if let stocks = stocks { | |
DispatchQueue.main.async { | |
self.stocks = stocks.map(StockViewModel.init) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment