Go to file
Max Sokolov 6f3daa337b support Swift Package Manager 2016-06-13 13:51:02 +03:00
Configs support Swift Package Manager 2016-06-13 13:51:02 +03:00
Demo support Swift Package Manager 2016-06-13 13:51:02 +03:00
Sources support Swift Package Manager 2016-06-13 13:51:02 +03:00
TableKit.xcodeproj support Swift Package Manager 2016-06-13 13:51:02 +03:00
Tests support Swift Package Manager 2016-06-13 13:51:02 +03:00
.gitignore remove useless code, add gitignore 2016-04-16 22:48:46 +03:00
.travis.yml rename to TableKit 2016-06-11 00:51:10 +03:00
LICENSE added podspec and license 2015-11-08 23:47:15 +03:00
Package.swift support Swift Package Manager 2016-06-13 13:51:02 +03:00
README.md update readme 2016-06-13 13:12:12 +03:00
TableKit.podspec support Swift Package Manager 2016-06-13 13:51:02 +03:00

README.md

#TableKit

Build Status Swift 2.2 compatible Platform iOS CocoaPods compatible License: MIT

TableKit is a super lightweight yet powerful generic library that allows you to build complex table views in a declarative type-safe manner. It hides a complexity of UITableViewDataSource and UITableViewDelegate methods behind the scene, so your code will be look clean, easy to read and nice to maintain.

Features

  • Type-safe cells based on generics
  • The easiest way to map your models or view models to cells
  • Correctly handles autolayout cells with multiline labels
  • Chainable cell actions (select/deselect etc.)
  • Support cells created from code, xib, or storyboard
  • Automatic xib/classes registration
  • No need to subclass
  • Extensibility
  • Tests

Usage

Create your rows:

let row1 = TableRow<String, StringTableViewCell>(item: "1")
let row2 = TableRow<String, IntTableViewCell>(item: 2)
let row3 = TableRow<String, FloatTableViewCell>(item: 3.0)

Put rows into section:

let section = TableSection(rows: [row1, row2, row3])

And setup your table:

let tableDirector = TableDirector(tableView: tableView)
tableDirector += section

Done. Your table is ready. You may want to look at your cell. It has to conform to ConfigurableCell protocol:

class StringTableViewCell: UITableViewCell, ConfigurableCell {

	typealias T = String

	func configure(string: T) {
		titleLabel.text = string
	}

	static func estimatedHeight() -> CGFloat {
        return 44
    }
}

You could have as many rows and sections as you need.

Row actions

It nice to have some actions that related to your cells:

let action = TableRowAction<String, StringTableViewCell>(.click) { (data) in

}

let row = TableRow<String, StringTableViewCell>(item: "some", actions: [action])

Or, using nice chaining approach:

let row = TableRow<String, StringTableViewCell>(item: "some")

row
	.addAction(TableRowAction(.click) { (data) in
	
	})
	.addAction(TableRowAction(.shouldHighlight) { (data) -> Bool in
		return false
	})

Batch rows

You could have a situation when you need a lot of cells with the same type. In that case it's better to use TableRowBuilder:

let builder = TableRowBuilder<String, StringTableViewCell> {

	// do some additional setup here
	$0.items = ["1", "2", "3"]
	$0.actions = [action]
}

section.append(builder: builder)

Or if you don't need an additional setup for your data, just use standart init:

let builder = TableRowBuilder<String, StringTableViewCell>(items: ["1", "2", "3"], actions: [actions])

section.append(builder: builder)

Installation

CocoaPods

To integrate TableKit into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'TableKit'

Carthage

Add the line github "johnsundell/unbox" to your Cartfile

Requirements

  • iOS 8.0+
  • Xcode 7.0+

License

TableKit is available under the MIT license. See LICENSE for details.