Skip to content

Latest commit

 

History

History
80 lines (57 loc) · 3.11 KB

README.md

File metadata and controls

80 lines (57 loc) · 3.11 KB

ReusableProtocol

CI Status Version License Platform Laguage CocoaPods LeoDev GitHub stars

🎏 ReusableProtocol is a helpful and pure Swift implemented library for registering and reusing cells or views in the table view and collection view. You may never care about what the reuse identifier is.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 8.0+

Installation

ReusableProtocol is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ReusableProtocol'

Usage

  • Register the cell or view:

    // UITableView
    tableView.register(TableViewCell.self)
    tableView.register(TableViewHeaderView.self)
    
    // UICollectionView
    collectionView.register(CollectionViewCell.self)
    collectionView.register(CollectionHeaderView.self,
                            forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader)
  • Dequeue the cell or view:

    // UITableView
    let cell = tableView.dequeueReusableCell(with: TableViewCell.self, for: indexPath)
    let view = tableView.dequeueReusableHeaderFooterView(with: TableViewHeaderView.self)
    
    // UICollectionView
    let cell = collectionView.dequeueReusableCell(with: CollectionViewCell.self, for: indexPath)
    let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, 
                                                               viewClass: CollectionHeaderView.self,
                                                               for: indexPath)
  • Optional: You may want to register the cell or view from nib:

    // UITableView
    tableView.register(TableViewCell.self, fromNib: true)
    tableView.register(TableViewHeaderView.self, fromNib: true)
    
    // UICollectionView
    collectionView.register(CollectionViewCell.self, fromNib: true)
    collectionView.register(CollectionHeaderView.self, 
                            forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
                            fromNib: true)

Author

Leo, leodaxia@gmail.com

License

ReusableProtocol is available under the MIT license. See the LICENSE file for more info.