Latest 1.3
License MIT
Platforms ios 9.0, requires ARC
Frameworks UIKit

Creating UITableViewCell and UICollectionViewCell subclasses is so Swift 2 point zero.

Pod Version
Swift Version
License MIT

Introducing, GenericCells!… Capitalizing on Swift’s generics, we can get all the benefits of a custom UITableViewCell or UICollectionViewCell class, without the hassle of a new class for each of them.

Let’s show you how to use it.

Create a UIView subclass for the layout you want:

final class MyView: UIView {

    let imageView: UIImageView
    let titleLabel: UILabel
    let subtitleLabel: UILabel
    // And add more views to your heart's content


Register the cell with a UITableView or UICollectionView:


Dequeue the cell with a UITableView or UICollectionView:

let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as GenericTableCell<MyView>
let cell = collectionView.dequeueReusableCell(forIndexPath: indexPath) as GenericCollectionCell<MyView>

And customize it to your heart’s content. The view you wish to access will be available via the .customView property:

cell.customView.titleLabel.text = "This library rules!"
cell.customView.imageView.image = UIImage(named: "success")

Extra credit, let’s add recycling support. Extend your view with the ReusableGenericView protocol:

extension MyView: ReusableGenericView {

    func prepareForReuse() {
        self.titleLabel.text = ""
        self.subtitleLabel.text = ""
        self.imageView.image = nil


And it will get called when the cell is recycled.


You can use CocoaPods to install GenericCells by adding it to your Podfile:

platform :ios, '9.0'

pod 'GenericCells'

Or install it manually by downloading GenericTableCell.swift, GenericCollectionCell.swift, and ReusableView.swift, and dropping it in your project.

About me

Hi, I’m Joe everywhere on the web, but especially on Twitter.


See the license for more information about how you can use GenericCells.

Is that it?

Yes, that’s it. And if you don’t like it, well sorry, here’s a rainbow. 🌈

Latest podspec

    "name": "GenericCells",
    "summary": "Taking advantage of generics instead of subclassing for UITableViewCell and UICollectionViewCell.",
    "version": "1.3",
    "license": {
        "type": "MIT"
    "authors": {
        "Joe Fabisevich": "[email protected]"
    "source_files": "Source/*.{swift}",
    "homepage": "",
    "source": {
        "git": "",
        "tag": "1.3"
    "platforms": {
        "ios": "9.0"
    "swift_version": "4.2",
    "requires_arc": true,
    "social_media_url": "",
    "frameworks": "UIKit"

Pin It on Pinterest

Share This