Last active
          November 12, 2021 16:40 
        
      - 
      
- 
        Save lordzsolt/da29cb97bf0faaa85d68fe154f51fdbb to your computer and use it in GitHub Desktop. 
    ReusableView.swift
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | extension ReusableView where Self: UIView { | |
| static var reuseIdentifier: String { | |
| return String(describing: self) | |
| } | |
| } | |
| extension UITableViewCell: ReusableView {} | |
| extension UITableViewHeaderFooterView: ReusableView {} | |
| extension UICollectionView: ReusableView {} | |
| extension UICollectionReusableView: ReusableView {} | 
  
    
      This file contains hidden or 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
    
  
  
    
  | extension UITableView { | |
| func register<T: UITableViewCell>(_: T.Type) { | |
| register(T.self, forCellReuseIdentifier: T.reuseIdentifier) | |
| } | |
| func register<T: UITableViewHeaderFooterView>(_: T.Type) { | |
| register(T.self, forHeaderFooterViewReuseIdentifier: T.reuseIdentifier) | |
| } | |
| func dequeueReusableCell<T: UITableViewCell>(forIndexPath indexPath: IndexPath) -> T { | |
| let cell = dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) | |
| return cell as! T | |
| } | |
| func dequeueHeaderFooterView<T: UITableViewHeaderFooterView>() -> T { | |
| let headerFooterView = dequeueReusableHeaderFooterView(withIdentifier: T.reuseIdentifier) as! T | |
| return headerFooterView | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment