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.
Swift Ruby Objective-C
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
FountainKit.xcodeproj
FountainKit
FountainKitDemo
FountainKitTests
Sources
Tests
.gitignore
.travis.yml
FountainKit.podspec
LICENSE
Package.swift
README.md

README.md

Build Status

FountainKit

FountainKit

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.

The problem FountainKit tries to solve

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.

The way FountainKit tries to solve the problem

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

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.

View Controller

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
    }

Integrating FountainKit in your project

FountainKit can be integrated using:

Carthage

github "ctarda/FountainKit"

CocoaPods

use frameworks!
pod 'FountainKit'

Swift Package Manager

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)
    ]
)

Examples

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/

Contributing to 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:

  • Add more implementations of the DataManager protocol, managing diferent data structures.
  • Expand to delegates!
  • Improve the current sample application, adding a sample integration of a collectionview.
  • Add some more documentation.

License

FountainKit is released under the MIT license