Skip to content

Instantly share code, notes, and snippets.

@fitsyu
Last active July 6, 2019 06:10
Show Gist options
  • Save fitsyu/3ca801235c275084fb5df406002b8c1f to your computer and use it in GitHub Desktop.
Save fitsyu/3ca801235c275084fb5df406002b8c1f to your computer and use it in GitHub Desktop.
A snippet to easily create the boilerplate UITableView DataSource and Delegate

INTEGRATE WITH XCODE

  1. Paste the code
  2. Highlight It
  3. Right click to open the context menu
  4. Select Create Code Snippet
  5. Set the platform to iOS and the language to Swift
  6. Set the scope to Top Level

HOW TO USE

  1. Get in the source code editor
  2. CTRL+SHIFT+L to open the snippet list
  3. Select this snippet
extension <#_#>: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return <#models#>.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: <#Model#>Cell.ID, for: indexPath) as! <#Model#>Cell
cell.data = models[indexPath.row]
return cell
}
}
extension <#_#>: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let model: <#Model#> = models[indexPath.row]
}
}
class <#Model#>Cell: UITableViewCell {
static let ID = ""
// @IBOutlet weak var label: UILabel!
var data: <#Model#>! {
didSet {
// label.text = data.person.name
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment