Skip to content
Dequer is a light weight library to deque Any Cell
Swift Ruby
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.swiftpm/xcode
Dequer.xcodeproj
Dequer
Source
docs
fastlane
.gitignore
.jazzy.yaml
.travis.yml
Dequer.podspec
Gemfile
Gemfile.lock
LICENSE.md
Package.swift
README.md

README.md

Dequer is Light weight library to handle Any Cell

Platforms Language Build Test Document License Requirement

Dequer

Dequer is a light weight library to handle Any Cell

One of the most used things in iOS development is deque UITableViewCell or UICollectionViewCell through DataSources and it has some configuration. I maded an extension and protocol which reuse a cell as clean as possible.

Availability

for the completion handler block used in protocol which is a closure , every Cell class should mark with final this means that can not be override this class or use it as superclass and block inheritance.

Protocol oriented

every Cell class which conforms to Dequer can use this code.

Extra

inside Cell there is a static variable named height for UITableViewCell and size for UICollectionViewCell which can store the default height of that cell. this one in optional and you can remove it.

Requirements

  • iOS 9.3+
  • Swift 4.0+

Also fully compatible with Swift version 5.x

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Dequer into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'Dequer', :git => 'https://github.com/mohamadrezakoohkan/Dequer.git'

Swift Package Manager

You can use The Swift Package Manager to install Dequer by adding the dequer package description to your Package.swift file:

// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        .package(url: "https://github.com/mohamadrezakoohkan/Dequer.git", from: "1.2.3"),
    ]
)

Then run swift build in Terminal to build Dequer.

Manually

If you prefer not to use any of the aforementioned dependency managers, you can use source code manually. get latest relase from Releases.

Usage

Example project

Clone the project and use example project for more. Also documents are available.

Example of how to implement Dequer in your project.

import UIKit
import Dequer

final class PersonCell: UITableViewCell, Dequer {

    static var height: CGFloat = 40

    override func awakeFromNib() {
        super.awakeFromNib()

    }

}
    

inside UITableViewDataSource

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    return PersonCell.deque(in: tableView, at: indexPath) { (cell, row) in
        cell.textLabel?.text = \(row)
    }
}

Data Binding

As binding data in cellForRowAt or cellForItemAt should be avoided, I maded a method called bind which can use for data binding In This Commit.

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    return AnimalCell.deque(in: collectionView, at: indexPath)
}

override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
    AnimalCell.bind(to: cell) {
        $0.animal = self.animals[indexPath.row]
    }
}

Contact

Follow and contact me on Instagram, Github, LinkedIn or stack overflow. If you find an issue open a ticket. You can send me email at mohamad_koohkan@icloud.com .

License

Dequer is released under the MIT license.

You can’t perform that action at this time.