Created
May 2, 2020 10:09
-
-
Save eonist/deede5d92330e03aa2c7e754cb30173b to your computer and use it in GitHub Desktop.
UITableView+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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