Skip to content

Instantly share code, notes, and snippets.

@yfujiki
Last active February 28, 2020 19:43
Show Gist options
  • Save yfujiki/45ce60ad14d8fdf054ca715fe5bb869e to your computer and use it in GitHub Desktop.
Save yfujiki/45ce60ad14d8fdf054ca715fe5bb869e to your computer and use it in GitHub Desktop.
Cache Label
private var labelCache = [IndexPath: UILabel]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
...
if labelCache[indexPath] == nil {
let label = UILabel()
label.text = ...
labelCache[indexPath] = label
}
let label = labelCache[indexPath]!
cell.contentView.addSubview(label)
...
return cell
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment