Skip to content

Instantly share code, notes, and snippets.

@FranDepascuali
Last active July 9, 2016 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FranDepascuali/df573fe214fa41f4d1ba808a1e37e453 to your computer and use it in GitHub Desktop.
Save FranDepascuali/df573fe214fa41f4d1ba808a1e37e453 to your computer and use it in GitHub Desktop.
protocol UIComponentType {
associatedtype Controller
associatedtype View
associatedtype ViewModel
func createController() -> Controller
func createView() -> View
func createViewModel() -> ViewModel
}
protocol LoginComponentType: UIComponentType {
associatedtype Controller: UIViewController, LoginControllerType
associatedtype View: UIView, LoginViewType
associatedtype ViewModel: LoginViewModelType
var delegate: LoginControllerDelegate { get }
var transitionDelegate: LoginControllerTransitionDelegate { get }
}
extension LoginComponentType {
func createController() -> LoginController {
let configuration = LoginControllerConfiguration(
viewModel: createViewModel(),
viewFactory: createView,
transitionDelegate: transitionDelegate)
return LoginController(configuration: configuration)
}
func createView() -> LoginView {
let view: LoginView = .loadFromNib()
let configuration = DefaultLoginViewConfiguration()
view.delegate = DefaultLoginViewDelegate(configuration: configuration)
return view
}
var delegate: LoginControllerDelegate {
return DefaultLoginControllerDelegate()
}
var transitionDelegate: LoginControllerTransitionDelegate {
return DefaultLoginControllerTransitionDelegate()
}
}
class AuthenticationBootstrapper<LoginComponent: LoginComponentType> {
private let _loginComponent: LoginComponent
init(loginComponent: LoginComponent){
_loginComponent = loginComponent
}
}
class DefaultLoginComponent: LoginComponentType {
typealias Controller = LoginController
typealias View = LoginView
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment