@StateObject private var vm = QuotesViewModelImpl(service: QuotesServiceImpl()) --> Error Here
var body: some View {
Group {
if vm.quotes.isEmpty {
LoadingView(text: "Fetching Quotes")
} else {
List {
ForEach(vm.quotes, id: \.anime) { quote in
QuoteView(quote: quote)
}
}
}
}
.task {
await vm.getRandomQuotes()
}
}
}
Here is the ViewModel:
final class QuotesViewModelImpl: QuotesViewModel {
@Published private(set) var quotes: [Quote] = []
private let service: QuotesService
init(service: QuotesService) async {
self.service = service
}
func getRandomQuotes() async {
do {
self.quotes = try await service.fetchRandomQuotes()
} catch {
print(error)
}
}
}