Skip to content

Instantly share code, notes, and snippets.

@zafarivaev
Created January 5, 2020 12:03
Show Gist options
  • Save zafarivaev/cbe1feb9509b4eef0651bfd913516852 to your computer and use it in GitHub Desktop.
Save zafarivaev/cbe1feb9509b4eef0651bfd913516852 to your computer and use it in GitHub Desktop.
import Foundation
class QuotesInteractor: PresenterToInteractorQuotesProtocol {
// MARK: Properties
weak var presenter: InteractorToPresenterQuotesProtocol?
var quotes: [APIQuote]?
func loadQuotes() {
print("Interactor receives the request from Presenter to load quotes from the server.")
QuoteService.shared.getQuotes(count: 10, success: { (code, quotes) in
self.quotes = quotes
self.presenter?.fetchQuotesSuccess(quotes: quotes)
}) { (code) in
self.presenter?.fetchQuotesFailure(errorCode: code)
}
}
func retrieveQuote(at index: Int) {
guard let quotes = self.quotes, quotes.indices.contains(index) else {
self.presenter?.getQuoteFailure()
return
}
self.presenter?.getQuoteSuccess(self.quotes![index])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment