Created
August 4, 2017 10:18
-
-
Save sgr-ksmt/2b00fe0950f579ad3fb76d90acb11fef to your computer and use it in GitHub Desktop.
DataSource
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
protocol DataSourceSection { | |
associatedtype Element | |
var elements: [Element] { get } | |
} | |
protocol DataSource { | |
associatedtype Section: DataSourceSection | |
var sections: [Section] { get } | |
} | |
extension DataSource { | |
func numberOfSections() -> Int { | |
return sections.count | |
} | |
func numberOfElements(in section: Int) -> Int { | |
return self[section].elements.count | |
} | |
subscript (section: Int) -> Section { | |
return sections[section] | |
} | |
subscript (indexPath: IndexPath) -> Section.Element { | |
return self[indexPath.section].elements[indexPath.row] | |
} | |
} |
Author
sgr-ksmt
commented
Aug 4, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment