Need help with ReusableKit?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

devxoul
142 Stars 19 Forks MIT License 67 Commits 5 Opened issues

Description

Generic reusables for UICollectionView and UITableView

Services available

!
?

Need anything else?

Contributors list

ReusableKit

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()
collectionView.register(reusableUserCell)
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
.

UITableView

// 1. define
enum Reusable {
  static let headerView = ReusableCell()
  static let userCell = ReusableCell()
}

// 2. register tableView.register(Reusable.headerView) tableView.register(Reusable.userCell)

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

UICollectionView

// 1. define
enum Reusable {
  static let headerView = ReusableCell()
  static let photoCell = ReusableCell()
}

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

// 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
  .bind(to: collectionView.rx.items(Reusable.userCell)) { i, user, cell in
    cell.user = user
  }

Contrubiting

Pull requests are welcomed 💖

In order to create Xcode project, run:

$ swift package generate-xcodeproj

Installation

  • For iOS 8+ projects with CocoaPods:

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

License

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.