rahimizad / JSQDataSourcesKit

Type-safe, value-oriented, composable data source objects that keep your view controllers light

Home Page:http://www.jessesquires.com/JSQDataSourcesKit/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSQDataSourcesKit

Build Status Version Status license MIT codecov.io Platform Carthage compatible

Type-safe, value-oriented, composable 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.0+

Installation

CocoaPods (recommended)

use_frameworks!

# For latest release in cocoapods
pod 'JSQDataSourcesKit'

# Feeling adventurous? Get the latest on develop
pod 'JSQDataSourcesKit', :git => 'https://github.com/jessesquires/JSQDataSourcesKit.git', :branch => 'develop'

Carthage

github "jessesquires/JSQDataSourcesKit"

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 is composed of different data source and delegate Provider classes. Instances of a Provider own a collection of model objects and a cell factory, and are responsible for providing a data source or delegate.

Read the blog post for more details! (written after the 3.0 release)

Example

The following illustrates a simple example of how these components interact for a table view. Using a collection view follows similarly.

// Given a view controller with a table view

// 1. register cells
let nib = UINib(nibName: "MyCellNib", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "MyCellIdentifier")

// 2. create sections with your model objects
let section0 = TableViewSection(items: /* items of type T */)
let section1 = TableViewSection(items: /* items of type T */)
let allSections = [section0, section1]

// 3. create cell factory
let factory = TableViewCellFactory(reuseIdentifier: "MyCellIdentifier") { (cell, model, tableView, indexPath) -> UITableViewCell in
      // configure the cell
      return cell
}

// 4. create data source provider
let dataSourceProvider = TableViewDataSourceProvider(sections: allSections, cellFactory: factory)

// 5. set the table view's data source
tableView.dataSource = dataSourceProvider.dataSource

Demo Project

The example app included exercises all functionality in this library. Open JSQDataSourcesKit.xcworkspace, select the Example scheme, then build and run.

Unit tests

There's a suite of unit tests for the JSQDataSourcesKit.framework. To run them, open JSQDataSourcesKit.xcworkspace, select the JSQDataSourcesKit scheme, then ⌘-u.

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.

About

Type-safe, value-oriented, composable data source objects that keep your view controllers light

http://www.jessesquires.com/JSQDataSourcesKit/

License:Other


Languages

Language:Swift 99.2%Language:Ruby 0.5%Language:Objective-C 0.3%