Skip to content

Instantly share code, notes, and snippets.

@Quaggie
Created September 11, 2017 12:02
Show Gist options
  • Select an option

  • Save Quaggie/e87670fbba9a00625c74009e1f57c19b to your computer and use it in GitHub Desktop.

Select an option

Save Quaggie/e87670fbba9a00625c74009e1f57c19b to your computer and use it in GitHub Desktop.
class DataSource: NSObject {
typealias Callback = ((IndexPath) -> Void)?
var names = [String]()
fileprivate var callback: Callback
init(names: [String]) {
super.init()
self.names = names
}
}
extension DataSource: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return UITableViewCell()
}
}
extension DataSource: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
callback?(indexPath)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment