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 UIKit | |
// MARK: View Input (View -> Presenter) | |
protocol ViewToPresenterQuotesProtocol { | |
var view: PresenterToViewQuotesProtocol? { get set } | |
var interactor: PresenterToInteractorQuotesProtocol? { get set } | |
var router: PresenterToRouterQuotesProtocol? { get set } | |
var quotesStrings: [String]? { get set } | |
func viewDidLoad() | |
func refresh() |
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
class QuotesPresenter: ViewToPresenterQuotesProtocol { | |
// MARK: Properties | |
weak var view: PresenterToViewQuotesProtocol? | |
var interactor: PresenterToInteractorQuotesProtocol? | |
var router: PresenterToRouterQuotesProtocol? | |
var quotesStrings: [String]? | |
// MARK: Inputs from view |
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
extension QuotesViewController: PresenterToViewQuotesProtocol{ | |
func onFetchQuotesSuccess() { | |
print("View receives the response from Presenter and updates itself.") | |
self.tableView.reloadData() | |
self.refreshControl.endRefreshing() | |
} | |
func onFetchQuotesFailure(error: String) { | |
print("View receives the response from Presenter with error: \(error)") |
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.") |
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
extension QuotesPresenter: InteractorToPresenterQuotesProtocol { | |
func fetchQuotesSuccess(quotes: [APIQuote]) { | |
print("Presenter receives the result from Interactor after it's done its job.") | |
self.quotesStrings = quotes.compactMap { $0.quote } | |
view?.hideHUD() | |
view?.onFetchQuotesSuccess() | |
} | |
func fetchQuotesFailure(errorCode: Int) { |
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 UIKit | |
class QuotesRouter: PresenterToRouterQuotesProtocol { | |
// MARK: Static methods | |
static func createModule() -> UINavigationController { | |
print("QuotesRouter creates the Quotes module.") | |
let viewController = QuotesViewController() | |
let navigationController = UINavigationController(rootViewController: viewController) |
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
// MARK: View Input (View -> Presenter) | |
protocol ViewToPresenterQuoteDetailProtocol { | |
var view: PresenterToViewQuoteDetailProtocol? { get set } | |
var interactor: PresenterToInteractorQuoteDetailProtocol? { get set } | |
var router: PresenterToRouterQuoteDetailProtocol? { get set } | |
func viewDidLoad() | |
} | |
// MARK: View Output (Presenter -> View) | |
protocol PresenterToViewQuoteDetailProtocol { |
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
class QuoteDetailViewController: UIViewController { | |
// MARK: - Lifecycle Methods | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupUI() | |
presenter?.viewDidLoad() | |
} |
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
class QuoteDetailPresenter: ViewToPresenterQuoteDetailProtocol { | |
// MARK: Properties | |
weak var view: PresenterToViewQuoteDetailProtocol? | |
var interactor: PresenterToInteractorQuoteDetailProtocol? | |
var router: PresenterToRouterQuoteDetailProtocol? | |
func viewDidLoad() { | |
print("Presenter is being notified that the View was loaded.") | |
interactor?.getImageDataFromURL() |
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
class QuoteDetailInteractor: PresenterToInteractorQuoteDetailProtocol { | |
// MARK: Properties | |
weak var presenter: InteractorToPresenterQuoteDetailProtocol? | |
var quote: APIQuote? | |
func getImageDataFromURL() { | |
print("Interactor receives the request from Presenter to get image data from the server.") | |
KingfisherService.shared.loadImageFrom(urlString: quote!.image!, success: { (data) in | |
self.presenter?.getImageFromURLSuccess(quote: self.quote!, data: data) |
OlderNewer