-
Notifications
You must be signed in to change notification settings - Fork 234
Closed
Labels
Description
Hi,
As the titles says. I've been using this approach for some time:
public extension UITableView {
/// Registers and dequeues a `Reusable` `UITableViewCell`.
///
/// - Returns: A reusable cell.
final func reusableCell<T: UITableViewCell>() -> T where T : Reusable {
guard let cell = self.dequeueReusableCell(withIdentifier: T.reuseIdentifier) as? T else {
self.register(T.self, forCellReuseIdentifier: T.reuseIdentifier)
return self.dequeueReusableCell(withIdentifier: T.reuseIdentifier) as! T
}
return cell
}
}Then:
let cell = tableView.reusableCell() as TableViewCellNo need to remind myself to register beforehand. I know the signatures don't match. It's just to get an idea.
Is there some edge case I'm not seeing where this might not be possible/advisable?
Thanks
kuyazee