Skip to content

Instantly share code, notes, and snippets.

@gwennguihal
Created October 1, 2019 07:09
Show Gist options
  • Save gwennguihal/13c5762b4ad27a3787fbeab83592ab40 to your computer and use it in GitHub Desktop.
Save gwennguihal/13c5762b4ad27a3787fbeab83592ab40 to your computer and use it in GitHub Desktop.
public class DataSource: NSObject {
public var sections = [Section]()
}
extension DataSource: UITableViewDataSource {
public func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let section = sections[section]
return section.cells.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let section = sections[indexPath.section]
guard let cell = section.cells[indexPath.item] else {
fatalError()
}
guard let uiCell = tableView.dequeueReusableCell(withIdentifier: cell.identifier, for: indexPath) as? UICell else {
fatalError()
}
uiCell.update(adapter: cell.getAdapter())
return uiCell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment