Created
January 5, 2020 12:03
-
-
Save zafarivaev/cbe1feb9509b4eef0651bfd913516852 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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