Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fmo91/dequeuableregistrable
Safe and convenient registering and dequeuing of UITableViewCells and UICollectionViewCells without using strings.
https://github.com/fmo91/dequeuableregistrable
ios protocol-oriented swift uicollectionview uitableview
Last synced: about 2 months ago
JSON representation
Safe and convenient registering and dequeuing of UITableViewCells and UICollectionViewCells without using strings.
- Host: GitHub
- URL: https://github.com/fmo91/dequeuableregistrable
- Owner: fmo91
- License: mit
- Created: 2017-01-06T00:32:12.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-02T18:30:25.000Z (almost 6 years ago)
- Last Synced: 2024-10-11T21:45:22.301Z (2 months ago)
- Topics: ios, protocol-oriented, swift, uicollectionview, uitableview
- Language: Swift
- Homepage: https://fmo91.github.io/DequeuableRegistrable/
- Size: 48.8 KB
- Stars: 12
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DequeuableRegistrable
[![CI Status](http://img.shields.io/travis/Fernando Ortiz/DequeuableRegistrable.svg?style=flat)](https://travis-ci.org/Fernando Ortiz/DequeuableRegistrable)
[![Version](https://img.shields.io/cocoapods/v/DequeuableRegistrable.svg?style=flat)](http://cocoapods.org/pods/DequeuableRegistrable)
[![License](https://img.shields.io/cocoapods/l/DequeuableRegistrable.svg?style=flat)](http://cocoapods.org/pods/DequeuableRegistrable)
[![Platform](https://img.shields.io/cocoapods/p/DequeuableRegistrable.svg?style=flat)](http://cocoapods.org/pods/DequeuableRegistrable)## Introduction
DequeuableRegistrable is a simple set of protocol extensions that allow registering and dequeuing cells and footers/headers (either from UITableView or UICollectionView) without using unsafe strings or explicit casting.
## Example Project
To run the example project, clone the repo, and run `pod install` from the Example directory first.
## Requirements
* iOS 9.0 or higher
* Swift 3.0 or higher## Installation
DequeuableRegistrable is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "DequeuableRegistrable", :git => "https://github.com/fmo91/DequeuableRegistrable/"
```## At a glance
DequeuableRegistrable turns registering from this:
```swift
tableView.register(UINib(nibName: "DogCell", bundle: nil), forCellReuseIdentifier: "DogCell")
```to this
```swift
DogCell.register(in: tableView)
```and turns dequeuing from this:
```swift
let cell = tableView.dequeueReusableCell(withIdentifier: "DogCell") as! DogCell
```to this:
```swift
let cell = DogCell.dequeue(from: tableView)
// cell is DogCell, not UITableViewCell. It's already casted.
```at the only cost of doing this:
```swift
extension DogCell: Registrable, Dequeuable {}
```## Usage
DequeuableRegistrable consists in three simple protocols:
1. `Identifiable`: It allows to identify any kind of object by providing a key string. In case of cells, that string is the reusable identifier.
2. `Dequeuable`: Inherits from Identifiable. It allows to dequeue cells from UICollectionView or UITableView using the reusable identifier provided by Identifiable protocol.
3. `Registrable`: Inherits from Identifiable. It allows to register cells in UICollectionView or UITableView using the reusable identifier provided by Identifiable protocol, and a nib object that Registrable protocol requires.All of these protocols have extensions that returns defaults values that match the class name. So, for example, if you have a `ABCCell` class, then its default reusable identifier would be `"ABCCell"`, and its `UINib` would be `UINib(nibName: "ABCCell")`
## Author
Fernando Ortiz, [email protected]
## License
DequeuableRegistrable is available under the MIT license. See the LICENSE file for more info.