I am using VIPER architecture with Swift.
I want to use protocol for presenter to get UITableView delegate, because I do not want to repeat the declarations of those methods for all presenters.
So I have created protocol
protocol TableViewPresenterProtocol: class {
associatedtype Data
func numberOfSections()-> Int
func haeaderTitle(secton: Int)-> String?
func numberOfRows(section: Int)-> Int
func itemForCell(at indexPath: IndexPath)-> Data
func didSelect(at indexPath: IndexPath)
}
//for make optional
extension TableViewPresenterProtocol {
func numberOfSections()-> Int {
return 1
}
func haeaderTitle(secton: Int)-> String? {
return nil
}
}
class PaymentViewController {
var presenter: (PaymentPresenterProtocol & TableViewPresenterProtocol)?
}
but XCode shows error
Protocol 'TableViewPresenterProtocol' can only be used as a generic constraint because it has Self or associated type requirements
Where in the source code do I fix that?