Git Product home page Git Product logo

fountainkit's Introduction

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

fountainkit's People

Contributors

ctarda avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

igorbiscanin

fountainkit's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.