Do You hate registering UITableViewCell
by String
identifier? Remembering all of them, some in Storyboards, some hidded somewhere in constants?
NO MORE! Use ReusableViewExtensions!
ReusableViewExtensions is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ReusableViewExtensions'
ReusableViewExtensions is available through Carthage. To install it, simply add the following line to your Cartfile:
github "agruchala/ReusableViewExtensions"
ReusableViewExtensions is available through Swift Package Manager. To install it, simply add the following git link to your packages:
https://github.com/agruchala/ReusableViewExtensions.git
- Swift 4.x
If You have installed framework everything should work out of the box for Your UITableViewCell
s and UICollectionViewCell
s. To use it when You want to get cell in data source
- add
import ReusableViewExtensions
to source file - use one of extension method from framework, thats it!
Having cell:
class MyCell: UITableViewCell { }
You don't need to add any comformance to cells, extension works for all UITableViewCell
and UICollectionViewCell
.
Use func register(_ cellType: Reusable.Type)
...
tableView.register(MyCell.self)
...
For cells with xib
files use func register(nibType: Reusable.Type, bundle: Bundle = .main)
Use func dequeue<T: Reusable>(for indexPath: IndexPath) -> T
//File header
import ReusableViewExtensions
//Your data source
...
let cell: MyCell = tableView.dequeue(for: indexPath)
...
Check Example to see how it works with xib
and cell added from code :)
To run the example project, clone the repo, and run pod install
from the Example directory first.
My name is Artur, I'm developer from Poland:)
ReusableViewExtensions is available under the MIT license. See the LICENSE file for more info.