https://github.com/gopherlabsltd/swiftydequeuable
⚡ A more simpler way to Dequeue Cells in Swift
https://github.com/gopherlabsltd/swiftydequeuable
cocoapods dequeue-cells elegant swift swift-4 uicollectionview uicollectionviewcell uitableview uitableviewcell
Last synced: 3 months ago
JSON representation
⚡ A more simpler way to Dequeue Cells in Swift
- Host: GitHub
- URL: https://github.com/gopherlabsltd/swiftydequeuable
- Owner: GopherLabsLtd
- License: mit
- Created: 2017-08-19T20:15:37.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-30T03:01:51.000Z (over 8 years ago)
- Last Synced: 2025-03-13T15:16:46.785Z (over 1 year ago)
- Topics: cocoapods, dequeue-cells, elegant, swift, swift-4, uicollectionview, uicollectionviewcell, uitableview, uitableviewcell
- Language: Shell
- Homepage:
- Size: 55.7 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/GopherLabsLtd/SwiftyDequeuable) [](https://img.shields.io/cocoapods/v/SwiftyDequeuable.svg)
[](http://cocoadocs.org/docsets/SwiftyDequeuable)
[]()
# SwiftyDequeuable
SwiftyDequeuable is a a more Elegant way to dequeue cells with a UITableView or a UICollectionView.
With Swift, we have the power of Protocol Oriented Programming + Protocol Extensions and with using Generics we can simplify these redundant processes.
We go from...
```swift
override func viewDidLoad() {
super.viewDidLoad()
let nibName = UINib(nibName: "SimpleLabelCell", bundle:nil)
tableView.registerNib(nibName, forCellReuseIdentifier: "SimpleLabelCell")
}
```
To something a little more Elegant...
```swift
override func viewDidLoad() {
super.viewDidLoad()
tableView.registerNib(SimpleLabelCell.self)
}
```
No more strings!
## Installation
### Cocoapods
```cocoapods
pod 'SwiftyDequeuable'
```
## Usage
Create a new cell with the corresponding .xib
```swift
import UIKit
class SimpleLabelCell: UITableViewCell {
@IBOutlet weak var label: UILabel!
}
```
In your ```viewDidLoad``` register your cell (or where ever you usually register your cells)
```swift
override func viewDidLoad() {
super.viewDidLoad()
tableView.registerNib(SimpleLabelCell.self)
}
```
In your ```cellForRowAt``` of your ```UITableViewDatasource``` you can dequeue the cell by...
```swift
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// If we cannot dequeue cell, a fatal error would be thrown.
let cell = tableView.dequeueReusableCell(SimpleLabelCell.self, forIndexPath: indexPath)
return cell
}
```
SwiftyDequeuable also supports ```UICollectionView```, the steps are very to the ones above. Have a look at the [Example](/SwiftyDequeuableExample).
## License
SwiftyDequeuable is released under an MIT license. See [License.md](License.md) for more information.