TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Mar 2016 |
SPMSupports SPM | ✓ |
Maintained by Cesar Tardaguila.
FountainKit is a lightweight Swift framework that attempts to decrease coupling between view controllers and datasources, and make data sources and cells easier to unit test.
Keeping view controllers small and focused is hard. View controllers, in particular those that need to present data, tend to do too much, to have too many responsibilites.
That makes those view controllers rigid, difficult to change, and dificult to unit test.
FountainKit is a lightweight framework that suggests a way to decouple datasources from view controllers, in a way that the datasources, the table view or collection view cells, and the view controllers can colaborate with each other and remain decoupled and testable.
Cells should be responsible for rendering their own content. In order to enforce that, table view and collection view cells must implement the DataSettable protocol:
public protocol DataSettable {
typealias DataType
var data: DataType? {get set}
}
DataType is the model object that will be provided to the cell.
A view controller should only be responsible for creating a data source, providing it the necessary data and a cell type, and then set it as the dataSource of the tableview / collectionview it controls.
private func initData() {
let data = [ Movie(title: "The Quiet Man", director: "John Ford"),
Movie(title: "The Third Man", director: "Carol Reed") ]
let dataManager = FlatArrayDataManager(data: data)
dataSource = TableViewDataSource(dataManager: dataManager, cellType: MovieCell.self)
}
private func initTableView() {
tableView.registerClass(MovieCell.self, forCellReuseIdentifier: MovieCell.cellReuseIdentifier())
tableView.dataSource = dataSource
}
FountainKit can be integrated using:
If you use the Swift Package Manager, add FountainKit to the dependencies of your Package.swift file:
import PackageDescription
let package = Package(
//
dependencies: [
//
.Package(url: "https://github.com/ctarda/FountainKit.git", majorVersion: 1, minor: 0)
]
)
This repository contains a sample app implementing a table view.
If you are interested in the rationale behind this framework, read this blog post: http://ctarda.com/2016/03/introducing-fountainkit/
Contributions of any kind (bug reports, feature suggestions, new features) are more than welcome, and greatly appreciated.
In particular, it would be necessary to:
FountainKit is released under the MIT license