ReusableViewExtensions
Do You hate registering UITableViewCell
by String
identifier? Remembering all of them, some in Storyboards, some hidded somewhere in constants?
NO MORE! Use ReusableViewExtensions!
Installation
CocoaPods
ReusableViewExtensions is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ReusableViewExtensions'
Carthage
ReusableViewExtensions is available through Carthage. To install it, simply add the following line to your Cartfile:
github "agruchala/ReusableViewExtensions"
Swift Package Manager
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
Requirements
- Swift 4.x
Usage
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!
Code snippet
Having cell:
class MyCell: UITableViewCell { }
You don't need to add any comformance to cells, extension works for all UITableViewCell
and UICollectionViewCell
.
Register it for table view
Use func register(_ cellType: Reusable.Type)
...
tableView.register(MyCell.self)
...
For cells with xib
files use func register(nibType: Reusable.Type, bundle: Bundle = .main)
Dequeue when needed without casting, just use type!
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 :)
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Author
My name is Artur, I'm developer from Poland:)
License
ReusableViewExtensions is available under the MIT license. See the LICENSE file for more info.