Skip to content

UITableView and UICollectionView extensions that allows to auto-register cells and extends both with simplified interfaces for dequeuing

License

Notifications You must be signed in to change notification settings

grzegorzkrukowski/CellRegistration

Repository files navigation

CellRegistration

Version License Platform

One line to rule them all

One-liner replacement for registering, dequeuing, casting cells for UITableView and UICollectionView

Instead of:

tableView.register(MyCustomCell.self, forCellReuseIdentifier: "MyCustomCell")
let cell : MyCustomCell = tableView.dequeueReusableCell(withIdentifier: "MyCustomCell", for: indexPath) as! MyCustomCell

you can now do only:

let : MyCustomCell = tableView.dequeueReusableCell(forIndexPath: indexPath)

No code refacotring needed, you can use that with existing projects that uses old-way. No need to worry about any registering, reuse identifiers, casting any more.

Cells loaded from nib files

Regardless the type of cell (loaded from code, or loaded from nib file), code is always the same:

Only requirement is to make a xib file with the same name as a class name.

let : MyCustomCell = tableView.dequeueReusableCell(forIndexPath: indexPath)
let : MyCustomCellLoadedFromXib = tableView.dequeueReusableCell(forIndexPath: indexPath)

or

tableView.dequeueReusableCell(forIndexPath: indexPath) as MyCustomCell
tableView.dequeueReusableCell(forIndexPath: indexPath) as MyCustomCellLoadedFromXib

This pod will search for a xib file that matches class name and register this nib automatically, otherwise it registers cell by class name.

Example

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

Installation

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

pod "CellRegistration"

Author

Grzegorz Krukowski, [email protected]

License

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

About

UITableView and UICollectionView extensions that allows to auto-register cells and extends both with simplified interfaces for dequeuing

Resources

License

Stars

Watchers

Forks

Packages

No packages published