Skip to content

Instantly share code, notes, and snippets.

@t0rn
Created October 21, 2019 19:16
Show Gist options
  • Save t0rn/c771365bce0e8b0025faf8a2d9a9d2a1 to your computer and use it in GitHub Desktop.
Save t0rn/c771365bce0e8b0025faf8a2d9a9d2a1 to your computer and use it in GitHub Desktop.
import Foundation
protocol DelegateProtocol: class {
}
protocol Delegatable {
associatedtype DelegateType: DelegateProtocol
var delegate: DelegateType? { get set }
}
protocol PresenterProtocol : Delegatable {
associatedtype View: ViewProtocol
var view:View {get}
}
protocol ViewProtocol: Delegatable {
}
protocol CoordinatorProtocol : Delegatable {
associatedtype From: ViewProtocol
associatedtype Destination: ViewProtocol
var from: From {get}
var destination:Destination {get}
}
class ListView<Delegate:DelegateProtocol> : ViewProtocol {
typealias DelegateType = Delegate
var delegate: Delegate?
init(delegate:Delegate? = nil) {
self.delegate = delegate
}
}
class ListPresenter<ListViewType:ViewProtocol, Delegate:DelegateProtocol> : PresenterProtocol {
typealias View = ListViewType
var view: ListViewType
var delegate: Delegate?
init(view:ListViewType,delegate:Delegate? = nil) {
self.view = view
self.delegate = delegate
}
}
class ListCoordinator<Delegate:DelegateProtocol,FromType:ViewProtocol, DestinationType:ViewProtocol> : CoordinatorProtocol {
typealias From = FromType
typealias Destination = DestinationType
typealias DelegateType = Delegate
var from: FromType
var destination: DestinationType
var delegate: Delegate?
init(from:FromType,
destination:DestinationType,
delegate:Delegate? = nil) {
self.from = from
self.destination = destination
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment