Skip to content
A helpful and pure Swift implemented library for registering and reusing cells or views in the table view and collection view.
Branch: master
Clone or download
Latest commit c8b83f7 Jul 8, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create FUNDING.yml Jul 8, 2019
Example style: update code style Jul 5, 2019
ReusableProtocol feat: finish example Jul 5, 2019
.gitignore Initial commit Jul 4, 2019
.travis.yml feat: update CI Jul 5, 2019
LICENSE feat: initial ReusableProtocol Jul 4, 2019
README.md style: update code style Jul 5, 2019
ReusableProtocol.podspec fix: .podspec Jul 5, 2019
_Pods.xcodeproj Initial commit Jul 4, 2019
_config.yml Set theme jekyll-theme-cayman Jul 4, 2019

README.md

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.

You can’t perform that action at this time.