Git Product home page Git Product logo

hakuba's Introduction

Hakuba

Platform Language License Issues

I want to slim down view controllers.

I want to manage tableview without the code of UITableViewDelegate and UITableViewDataSource.

That is why I created Hakuba.

( Hakuba is one of the most famous ski resorts in Japan. )

Features

  • Don't have to write the code for UITableViewDelegate and UITableViewDataSource protocols
  • Easy to manage your sections and cells (append/reset/insert/remove/update)
  • Support dynamic cell height from ios7
  • Don't have to worry about cell identifier
  • Handling cell selection by trailing closure
  • Easy to implement header/footer view (floating callback)
  • Support for creating cells from Nibs or Storyboards
  • Method chaining
  • Subscript
  • Support loadmore closure
  • Complete example
Quick example
	// viewController swift file

	hakuba = Hakuba(tableView: tableView)

	let cellmodel = YourCellModel(title: "Title", des: "description") {
		println("Did select cell with title = \(title)")
	}

	hakuba[2]
		.append(cellmodel)		// append a new cell model into datasource
		.bump(.Fade)			// show the cell of your cell model in the table view

	hakuba[1]
		.remove(1...3)
		.bump(.Right)
	// your cell swift file

	class YourCellModel: CellModel {
		let title: String
		let des: String

		init(title: String, des: String, selectionHandler: SelectionHandler) {
			self.title = title
			self.des = des
			super.init(YourCell.self, selectionHandler: selectionHandler)
		}
	}


	class YourCell: Cell, CellType {
		typealias CellModel = YourCellModel

		@IBOutlet weak var titleLabel: UILabel!

		override func configure() {
			guard let cellmodel = cellmodel else {
				return
			}

			titleLabel.text = cellmodel.title
      	}
	}

Usage

  • Initilization
	private lazy var hakuba = Hakuba(tableView: tableView)   
  • Section handling
	let section = Section() // create a new section

	// inserting
	hakuba
		.insert(section, atIndex: 1)
		.bump()

	// removing
	hakuba
		.remove(index)
		.bump(.Left)

	hakuba
		.remove(section)
		.bump()

	hakuba
		.removeAll()
		.bump()

	// handing section index by enum
	enum YourSection: Int, SectionIndexType {
		case Top = 0
		case Center
		case Bottom

		static let count = 3
	}
	
	let topSection = hakuba[YourSection.Top]
  • Cell handling
	// 1. appending
	hakuba[0]
		.append(cellmodel)				// append a cellmodel
		.bump(.Fade)					// and bump with `Fade` animation

	hakuba[1]
		.append(cellmodels)				// append a list of cellmodes
		.bump(.Left)					

	// by using section
	let section = hakuba[YourSection.Top]
	section
		.append(cellmodel)
		.bump()


	// 2. inserting
	section
		.insert(cellmodels, atIndex: 1)
		.bump(.Middle)


	// 3. reseting
	section
		.reset(cellmodels)				// replace current data in section by the new data
		.bump()

	section
		.reset()							// or remove all data in section
		.bump()


	// 4. removing
	section
		.remove(1)
	   	.bump(.Right)

	section
		.remove(2...5)
		.bump()

	section
		.removeLast()
	   	.bump()
	// updating cell data
	let section = hakuba[YourSection.Top]
	section[1].property = newData
	section[1]
		.bump()		
	section.sort().bump()
	section.shuffle().bump()
	section.map
	section.filter
	section.reduce
	section.mapFilter
	section.each

	section.first
	section.last
	section[1]
	section.count
  • Register cell, header, footer
	hakuba
		.registerCellByNib(CellClass)

	hakuba
		.registerCell(CellClass)

	hakuba
		.registerHeaderFooterByNib(HeaderOrFooterClass)

	hakuba
		.registerHeaderFooter(HeaderOrFooterClass)

	// register a list of cells by using variadic parameters
	hakuba.registerCellByNibs(CellClass1.self, CellClass2.self, ..., CellClassN.self)
  • Section header/footer
	let header = HeaderFooterViewModel(view: CustomHeaderView) {
		println("Did select header view")
	}
	hakuba[Section.Top].header = header
  • Loadmore
	hakuba.loadmoreEnabled = true
	hakuba.loadmoreHandler = {
		// request api
		// append new data
	}
  • Commit editing
	hakuba.commitEditingHandler = { [weak self] style, indexPath in
		self?.hakuba[indexPath.section]
			.remove(indexPath.row)
	}
  • Deselect all cells
	hakuba.deselectAllCells(animated: true)
  • Dynamic cell height : when you want to enable dynamic cell height, you only need to set the value of estimated height to the height parameter and set dynamicHeightEnabled = true
	let cellmodel = CellModel(cellClass: YourCell.self, height: 50, userData: yourCellData) {
		println("Did select cell")
	}
	cellmodel.dynamicHeightEnabled = true
  • Callback methods in the cell class
	func willAppear(data: CellModel)
	func didDisappear(data: CellModel)

Installation

  • Installation with CocoaPods
	pod 'Hakuba'
  • Copying all the files into your project
  • Using submodule

Requirements

  • iOS 7.0+
  • Xcode 6.1

License

Hakuba is released under the MIT license. See LICENSE for details.

hakuba's People

Contributors

nghialv avatar ikesyo avatar

Watchers

Denis Sushko avatar James Cloos avatar Andrey K avatar  avatar Mikhail Naryshkin avatar

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.