Created
October 19, 2019 12:29
-
-
Save karlis/d3ef2f7fa7c601a6a0e400a4c4e6a1e9 to your computer and use it in GitHub Desktop.
ReusableCell for easy dequeueing in UITableView.
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
/// ReusableCell for easy dequeueing in table views. Use UITableView.dequeueReusableCell(). | |
protocol ReusableCell { | |
static var reuseIdentifier: String { get } | |
init() | |
} | |
extension UITableView { | |
/// Dequeues a ReusableCell or allocates a new ReusableCell. | |
func dequeueReusableCell<Cell: ReusableCell>() -> Cell { | |
return dequeueReusableCell(withIdentifier: Cell.reuseIdentifier) as? Cell ?? Cell() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment