Created
June 29, 2020 05:11
-
-
Save asisadh/9c84eb7e2efa94940b839830cc7f4098 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 UIKit | |
// MARK:- General Protocols | |
protocol ViewProtocol: class{ | |
func showError(message: String) | |
func showLoading() | |
func hideLoading() | |
func refreshView() | |
} | |
protocol WireFrameProtocol: class{ | |
func redirectToLoginScreen_inValidateAndRemoveUserSession(from view: ViewProtocol) | |
} | |
extension WireFrameProtocol{ | |
func redirectToLoginScreen_inValidateAndRemoveUserSession(from view: ViewProtocol){ | |
if let view = view as? UIViewController{ | |
let loginView = LoginViewWireFrame.createLoginViewModule() | |
loginView.modalPresentationStyle = .fullScreen | |
view.present(loginView, animated: true, completion: nil) | |
} | |
} | |
} | |
protocol InteractorOutputProtocol: class { | |
var view: ViewProtocol? { get set } | |
var wireFrame: WireFrameProtocol? { get set } | |
// Interactor -> Presenter | |
func onError(message: String) | |
func onLoginTokenExpired(message: String) | |
} | |
// MARK:- Protocols for Home View | |
protocol HomeViewProtocol: ViewProtocol { | |
var presenter: HomeViewPresenterProtocol? { get set } | |
} | |
protocol HomeViewPresenterProtocol: class { | |
var view: HomeViewProtocol? { get set } | |
// var interactor: HomeViewInteractorInputProtocol? { get set } | |
var wireFrame: HomeViewWireFrameProtocol? { get set } | |
var categoriesTop: [String] { get set } | |
var myTopPicks: [String] { get set } | |
// View -> Presenter | |
func viewDidLoad() | |
} | |
protocol HomeViewInteractorOutputProtocol: InteractorOutputProtocol{ | |
func didFetchData(categoriesTop: [String]?, myTopPicks: [String]?) | |
} | |
protocol HomeViewWireFrameProtocol: WireFrameProtocol { | |
static func createHomeViewModel() -> UIViewController | |
// Presenter -> WireFrame | |
} | |
// MARK:- Implementation of Home class | |
class HomeViewWireframe: HomeViewWireFrameProtocol{ | |
static func createHomeViewModel() -> UIViewController{ | |
let viewController = HomeView() | |
let view = viewController as HomeViewProtocol | |
let presenter: HomeViewPresenterProtocol & HomeViewInteractorOutputProtocol = HomeViewPresenter() | |
let wireFrame: HomeViewWireFrameProtocol = HomeViewWireframe() | |
view.presenter = presenter | |
presenter.view = view | |
presenter.wireFrame = wireFrame | |
return viewController | |
} | |
} | |
class HomeView: UIViewController, HomeViewProtocol{ | |
var presenter: HomeViewPresenterProtocol? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
presenter?.viewDidLoad() | |
} | |
func showError(message: String){} | |
func showLoading(){} | |
func hideLoading(){} | |
func refreshView(){} | |
} | |
class HomeViewPresenter: HomeViewPresenterProtocol, HomeViewInteractorOutputProtocol{ | |
var view: HomeViewProtocol? | |
var wireFrame: HomeViewWireFrameProtocol? | |
var categoriesTop: [String] = [] | |
var myTopPicks: [String] = [] | |
// View -> Presenter | |
func viewDidLoad(){} | |
// implemented from HomeViewInteractorOutputProtocol | |
func didFetchData(categoriesTop: [String]?, myTopPicks: [String]?){} | |
// implemented from InteractorOutputProtocol | |
func onError(message: String){} | |
func onLoginTokenExpired(message: String){} | |
} | |
// MARK:- Helpers To make Test Possible | |
class LoginViewWireFrame{ | |
static func createLoginViewModule() -> UIViewController{ | |
return UIViewController() | |
} | |
} | |
/// Errors | |
// error: MyPlayground.playground:98:7: error: type 'HomeViewPresenter' does not conform to protocol 'InteractorOutputProtocol' | |
// class HomeViewPresenter: HomeViewPresenterProtocol, HomeViewInteractorOutputProtocol{ | |
// ^ | |
// MyPlayground.playground:99:9: note: candidate has non-matching type 'HomeViewProtocol?' | |
// var view: HomeViewProtocol? | |
// ^ | |
// MyPlayground.playground:100:9: note: candidate has non-matching type 'HomeViewWireFrameProtocol?' | |
// var wireFrame: HomeViewWireFrameProtocol? | |
// ^ | |
// MyPlayground.playground:26:9: note: protocol requires property 'view' with type 'ViewProtocol?'; do you want to add a stub? | |
// var view: ViewProtocol? { get set } | |
// ^ | |
// MyPlayground.playground:27:9: note: protocol requires property 'wireFrame' with type 'WireFrameProtocol?'; do you want to add a stub? | |
// var wireFrame: WireFrameProtocol? { get set } | |
// ^ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment