Swiftpack.co -  devxoul/ReusableKit as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Generic reusables for UICollectionView and UITableView
.package(url: "https://github.com/devxoul/ReusableKit.git", from: "3.0.0")


Swift CocoaPods Build Status Codecov

Generic reusables for Cocoa. Currently supports UITableView and UICollectionView.

At a Glance

Before 🤢

collectionView.register(UserCell.self, forCellWithReuseIdentifier: "userCell")
collectionView.dequeueReusableCell(withReuseIdentifier: "userCell", for: indexPath) as! UserCell
  1. A hard-coded string identifier can cause a human error.
  2. A force downcasting should be avoided.

After 😊

let reusableUserCell = ReusableCell<UserCell>()
collectionView.dequeue(reusableUserCell) // UserCell
  1. A string identifier is generated automatically using UUID and stored in the struct.
  2. A generic can ensure the type of the dequeued cell statically.

Example Usage

It is recommended to define reusable types as a static constants in an enum or a struct.


// 1. define
enum Reusable {
  static let headerView = ReusableCell<SectionHeaderView>()
  static let userCell = ReusableCell<UserCell>()

// 2. register

// 3. dequeue
tableView.dequeue(Reusable.headerView, for: indexPath)
tableView.dequeue(Reusable.userCell, for: indexPath)


// 1. define
enum Reusable {
  static let headerView = ReusableCell<SectionHeaderView>()
  static let photoCell = ReusableCell<PhotoCell>()

// 2. register
collection.register(Reusable.headerView, kind: .header)

// 3. dequeue
collection.dequeue(Reusable.headerView, kind: .header, for: indexPath)
collection.dequeue(Reusable.photoCell, for: indexPath)

RxSwift Extension

ReusableKit supports a RxSwift extension.

users // Observable<[String]>
  .bind(to: collectionView.rx.items(Reusable.userCell)) { i, user, cell in
    cell.user = user


Pull requests are welcomed 💖

In order to create Xcode project, run:

$ swift package generate-xcodeproj


  • For iOS 8+ projects with CocoaPods:

    pod 'ReusableKit'
    pod 'ReusableKit/RxSwift'  # with RxSwift extension


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


Stars: 137
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.


Release Notes

2 years ago
  • Add Swift 5 support 🚀 (#9)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API