All Projects → jayway → CollectionAndTableViewCompatible

jayway / CollectionAndTableViewCompatible

Licence: Apache-2.0 License
A set of Swift protocols and Xcode snippets that will make it easy to do clean UITableView code

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to CollectionAndTableViewCompatible

Rglistkit
RGListKit is a Protocol & MVVM based framework to easily populate a UITableView or UICollectionView via single api.
Stars: ✭ 178 (+423.53%)
Mutual labels:  uitableview, uicollectionview, protocol
Tabanimated
A skeleton screen framework based on native for iOS. (一个由iOS原生组件映射出骨架屏的框架,包含快速植入,低耦合,兼容复杂视图等特点,提供国内主流骨架屏动画的加载方案,同时支持上拉加载更多、自定制动画。)
Stars: ✭ 2,909 (+8455.88%)
Mutual labels:  uitableview, uicollectionview
Flowkit
A declarative type-safe framework for building fast and flexible list with Tables & Collection
Stars: ✭ 215 (+532.35%)
Mutual labels:  uitableview, uicollectionview
Cyanic
Declarative, state-driven UI framework
Stars: ✭ 32 (-5.88%)
Mutual labels:  uitableview, uicollectionview
Hgplaceholders
Nice library to show placeholders and Empty States for any UITableView/UICollectionView in your project
Stars: ✭ 2,048 (+5923.53%)
Mutual labels:  uitableview, uicollectionview
Swiftycomments
UITableView based component designed to display a hierarchy of expandable/foldable comments.
Stars: ✭ 200 (+488.24%)
Mutual labels:  uitableview, cocoapod
IQListKit
Model driven UITableView/UICollectionView
Stars: ✭ 51 (+50%)
Mutual labels:  uitableview, uicollectionview
Gskstretchyheaderview
A generic stretchy header for UITableView and UICollectionView
Stars: ✭ 1,624 (+4676.47%)
Mutual labels:  uitableview, uicollectionview
PagedLists
Paginated UITableView and UICollectionViews for iOS.
Stars: ✭ 69 (+102.94%)
Mutual labels:  uitableview, uicollectionview
TinyCoordinator
The Swift version of ThinningCoordinator focus on lighter view controllers.
Stars: ✭ 18 (-47.06%)
Mutual labels:  uitableview, uicollectionview
GenericCells
Creating generic UITableViewCells and UICollectionViewCells instead of subclasses.
Stars: ✭ 81 (+138.24%)
Mutual labels:  uitableview, uicollectionview
Vbpiledview
Simple and beautiful stacked UIView to use as a replacement for an UITableView, UIImageView or as a menu
Stars: ✭ 164 (+382.35%)
Mutual labels:  uitableview, uicollectionview
Closures
Swifty closures for UIKit and Foundation
Stars: ✭ 1,720 (+4958.82%)
Mutual labels:  uitableview, uicollectionview
Genericdatasource
A generic small reusable components for data source implementation for UITableView/UICollectionView in Swift.
Stars: ✭ 127 (+273.53%)
Mutual labels:  uitableview, uicollectionview
Transfiguration
Mystical way to transform data into reusable view in Swift
Stars: ✭ 14 (-58.82%)
Mutual labels:  uitableview, uicollectionview
Squaremosaiclayout
An extandable mosaic UICollectionViewLayout with a focus on extremely flexible customizations 🔶
Stars: ✭ 243 (+614.71%)
Mutual labels:  uitableview, uicollectionview
Basecomponents
BaseComponents aims to provide easily reusable and understandable components to increase productivity with UIKit and Foundation APIs
Stars: ✭ 92 (+170.59%)
Mutual labels:  uitableview, uicollectionview
Skeletonview
☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
Stars: ✭ 10,804 (+31676.47%)
Mutual labels:  uitableview, uicollectionview
HDEmptyView
一个Swift语言封装的EmptyView显示库,可作用于WKWebView、UITableView、UICollectionView 无网络提醒或者空数据提醒
Stars: ✭ 29 (-14.71%)
Mutual labels:  uitableview, uicollectionview
ios ui recipe showcase
iOSアプリ開発 - UI実装であると嬉しいレシピブック掲載サンプル
Stars: ✭ 54 (+58.82%)
Mutual labels:  uitableview, uicollectionview

CollectionAndTableViewCompatible

Version License Platform Carthage Compatible

CollectionAndTableViewCompatible provides the boilerplate code needed for writing UITableViewDataSource and UICollectionViewDataSource implementations. In fact, when using the classes provided here, in most cases you wont have to write these implementations at all.

Why you should use CollectionAndTableViewCompatible

Weather you are creating a new data source from scratch or you need to refactor old code that is getting hard to maintain you can probably benefit from adding CollectionAndTableViewCompatible to your project.

If you can say yes to one or more of the following this project is relevant to you:

  • Your UIViewController is your data source.
  • You like to keep your view controllers lightweight by separating out responsibility to relevant objects.
  • You do not want to write boilerplate code.
  • Your table or collection view consists of different cells with different layouts.
  • You want to be able to change the layout of your table or collection view and it's cells fast (for instance to respond to design changes).
  • Your table or collection view supports reordering or editing.
  • Your existing table/collection view data source is tigthly coupled with the type of entities it presents.
  • Your cellForRowAtIndexPath: is deciding which cell to return by switching on the section and row properties on the IndexPath parameter.
  • Your cellForRowAtIndexPath: is handling laying out the cells.

The basics

The main idea behind CollectionAndTableViewCompatible is to make the data model, that is backing you table/collection view, more compatible with the data source protocols (UITableViewDataSource and UICollectionViewDataSource).

CollectionAndTableViewCompatible does so by providing a default and completely generic implementation of the two data source protocols so that changes made to your model (for instance an array holding you model entities) will be reflected directly in the table/collection view. It also provides a couple of protocols that will help you delegate work like laying out cells, reordering and editing, to the relevant objects.

Finally it provides a few other protocols that enables support for the display cycle of cells (willDisplay and didEndDisplay) and the new data source prefetching protocols (UITableViewDataSourcePrefetching and UICollectionViewDataSourcePrefetching).

CocoaPods

If you are using CocoaPods you can run the example project by adding the pod (see below) and running pod install from the Example directory.

Requirements

  • Swift4
  • iOS 9+
  • Xcode8

Support for older version(s)

  • Swift3 is supported on older branches/pods. Use pod version 0.1.5.

Note that 0.2.x contains breaking changes if you update from 0.1.x

Installation

Swift Package Manager

SPM is supported from version 0.2.5. Specify location: https://github.com/jayway/CollectionAndTableViewCompatible

Git submodule

Add this project as a git submodule by running the following command from the root of you existing git repo:

git submodule add https://github.com/jayway/CollectionAndTableViewCompatible.git

When the submodule is cloned, add the files contained in the Classes folder to your Xcode project (make sure "Copy if needed" is unchecked).

CocoaPods

CollectionAndTableViewCompatible is also available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CollectionAndTableViewCompatible"

Carthage

github "jayway/CollectionAndTableViewCompatible"

How to use

The project is designed to be used in a storyboard based application using prototype cells. For now, if you are using nibs or you are creating UI entirely in code you will have to manually register nibs or classes to you table/collection view.

These are the steps you need to perform to setup your table/collection view:

  • Make your model object conform to the TableViewCompatible and/or CollectionViewCompatible protocol.
  • Create a UITableViewCell and/or UIColllectionViewCell subclass and let them conform to the Configurable protocol. The model property type should be the type of your model object.
  • Create a subclass of TableViewDataSource and/or CollectionViewDataSource and initialize it by calling init(tableView: UITableView) and/or init(collectionView: UICollectionView).
  • Initialize the sections property of you data source instance by providing TableViewSection/CollectionViewSection instances containing your model objects.
  • Call reloadData() on you table/collection view.

You are now free to add, remove and reorder sections and cells simply by modifying the sections property of your data source and calling reloadData() on the table/collection view.

To make your cells movable or editable, simply return true for the movable or editable properties of your TableViewCompatible/CollectionViewCompatible model object.

Below is an example of how the TableViewCompatible/CollectionViewCompatible and Configurable interacts when implemented:

class MyTableCell: UITableViewCell, Configurable {
    
    var model: MyCellModel?

    func configureWithModel(_ model: MyCellModel) {
        self.model = model
        titleLabel.text = model.title
    }

}

class MyCollectionCell: UICollectionViewCell, Configurable {

    @IBOutlet weak var titleLabel: UILabel!

    var model: MyCellModel?

    func configureWithModel(_ model: MyCellModel) {
        self.model = model
        titleLabel.text = model.title
    }

}

class MyCellModel: TableViewCompatible, CollectionViewCompatible {

    // Your custom properties
    var title: String = "Some title"

    // TableViewCompatible/CollectionViewCompatible conformance
    var reuseIdentifier: String = "MyCellIdentifier"
    var selected: Bool = false
    var editable: Bool = true
    var movable: Bool = true

    // TableViewCompatible
    func cellForTableView(tableView: UITableView, atIndexPath indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as! MyTableCell
        cell.configureWithModel(self)
        return cell
    }

    // CollectionViewCompatible
    func cellForCollectionView(collectionView: UICollectionView, atIndexPath indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! MyCollectionCell
        cell.configureWithModel(self)
        return cell
    }

}

Author

License

CollectionAndTableViewCompatible is available under the Apache License Version 2.0. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].