JSQDataSourcesKit 7.0.0

JSQDataSourcesKit 7.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jan 2018
SPMSupports SPM

Maintained by Jesse Squires.


Downloads

Total127,634
Week0
Month0

Installs

Apps351
Test Targets57
powered by Segment

GitHub

Stars607
Watchers26
Forks39
Issues16
Contributors6
Pull Requests2

Code

Files9
LOCLines of Code 659


JSQDataSourcesKit

Protocol-oriented, type-safe data source objects that keep your view controllers light

A Swift library of data source and delegate objects inspired by Andy Matuschak’s type-safe, value-oriented collection view data source gist.

About

This library reduces the boilerplate code regarding the UITableView, UICollectionView, and NSFetchedResultsController data source objects, as well as the NSFetchedResultsControllerDelegate object. It helps keep view controllers light, while focusing on type-safety, SOLID design principles, and easy interoperability with Cocoa. Further, it brings a more focused and data-driven perspective to these data sources. If you want to change your view then you change your data and its structure, without needing to update any data source or delegate protocol methods.

Requirements

  • iOS 8+
  • Swift 2.3
  • Xcode 8

Documentation

Read the docs. Generated with jazzy. Hosted by GitHub Pages.

More information on the gh-pages branch.

Getting Started

import JSQDataSourcesKit

Design

This library has four primary components:

  1. Section — represents a section of data
  2. DataSource — represents a collection of Section types
  3. ReusableViewFactory — responsible for dequeuing and configuring cells (for UITableView or UICollectionView)
  4. DataSourceProvider — owns a data source and cell factory, and provides a UICollectionViewDataSource or UITableViewDataSource object.

Example

The following illustrates a simple example of how these components interact for a collection view.

// Given a view controller with a collection view

// 1. create Sections and a DataSource with your model objects
let section0 = Section(items: ...)
let section1 = Section(items: ...)
let section2 = Section(items: ...)
let dataSource = DataSource(sections: section0, section1, section2)

// 2. create cell factory
let cellFactory = ViewFactory(reuseIdentifier: "CellId") { (cell, model?, type, collectionView, indexPath) -> MyCellClass in
    // configure the cell with the model
    return cell
}

// 3. create supplementary view factory
let type = ReusableViewType.supplementaryView(kind: UICollectionElementKindSectionHeader)
let headerFactory = ViewFactory(reuseIdentifier: "HeaderId", type: type) { (view, model?, type, collectionView, indexPath) -> MyHeaderView in
    // configure header view
    return view
}

// 4. create data source provider
let dataSourceProvider =  DataSourceProvider(dataSource: dataSource,
                                             cellFactory: cellFactory,
                                             supplementaryFactory: headerFactory)

// 5. set the collection view's data source
collectionView.dataSource = dataSourceProvider.collectionViewDataSource

Demo Project

The example project included exercises all functionality in this library.

Unit tests

There’s a suite of unit tests for JSQDataSourcesKit. Run them in the usual way from Xcode. These tests are well commented and serve as further documentation for how to use this library.

Contribute

Please follow these sweet contribution guidelines.

Credits

Created and maintained by @jesse_squires.

License

JSQDataSourcesKit is released under an MIT License. See LICENSE for details.

Copyright © 2015-present Jesse Squires.

Please provide attribution, it is greatly appreciated.