Skip to content

Instantly share code, notes, and snippets.

@eonist
Created May 2, 2020 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eonist/deede5d92330e03aa2c7e754cb30173b to your computer and use it in GitHub Desktop.
Save eonist/deede5d92330e03aa2c7e754cb30173b to your computer and use it in GitHub Desktop.
UITableView+Extension.swift
import UIKit
extension UITableViewDataSource where Self: UITableView {
/**
* Returns a cells in table
* - Note: Unlike native cell(for index) or visibleCells calls, this call wont break/complain even when called before the cells are available
*/
var availableCells: [UITableViewCell] {
self.subviews.compactMap { $0 as? UITableViewCell }
}
/**
* Returns a cell in table for indexpath
* - Note: Unlike native cell(for index) or visibleCells calls, this call wont break/complain even when called before the cells are available
*/
func availableCell(indexPath: IndexPath) -> UITableViewCell? {
availableCells.first { self.indexPath(for: $0) == indexPath }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment