• Stars
    star
    474
  • Rank 92,640 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 10 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🌸 Cellmodel-driven tableview manager

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: @escaping (Cell) -> Void) {
		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, at: 1)
	.bump()

// removing
hakuba
	.remove(at: index)
	.bump(.left)

hakuba
	.remove(section)
	.bump()

hakuba
	.removeAll()
	.bump()

// handing section index by enum
enum YourSection: Int, SectionIndexType {
	case top
	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, at: 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(at: 1)
	.bump(.right)

section
	.remove(range: 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.self)

hakuba
	.registerCell(CellClass.self)

hakuba
	.registerHeaderFooterByNib(HeaderOrFooterClass.self)

hakuba
	.registerHeaderFooter(HeaderOrFooterClass.self)

// 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)
  • 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 9.0+
  • Xcode 9+
  • Swift 4

License

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

More Repositories

1

MaterialKit

Material design components for iOS written in Swift
Swift
2,504
star
2

promviz

Visualize the traffic of your clusters in realtime from Prometheus data
Go
955
star
3

Transporter

A tiny library makes uploading and downloading easier
Swift
452
star
4

Net

Http Request wrapper written in Swift
Swift
302
star
5

Sapporo

Cellmodel-driven collectionview manager
Swift
246
star
6

Future

Swift µframework providing Future<T, Error>
Swift
122
star
7

GCD

A wrapper of Grand Central Dispatch written in Swift
Swift
72
star
8

Try

Swift µframework providing Try<T>
Swift
32
star
9

openGL-tankgame

A simple 3D game using openGL
C++
23
star
10

TVDataSource

datasource class for uitableview
Objective-C
17
star
11

gamegl

the bottom part of puzzle dragon game using OpenglES (without any framework)
Objective-C
14
star
12

iBall

iPhone, iPad間のバトルゲーム (OpenGLES)
C
6
star
13

VersionTracker

Tracking the app version
Swift
4
star
14

clibs

Central repository containing C libraries for testing
C
3
star
15

opencv-optical-flow

OpenCV, Python
Python
3
star
16

xcode_project_templates

xcode project templates
Objective-C
3
star
17

Kinect-ARToolKit

some simple examples of using Kinect (OpenNI) and ARToolKit
C++
2
star
18

vlcamera

vlcamera app
Objective-C
2
star
19

funnytext

render text in some shapes, change the position and orientation of each character
Objective-C
2
star
20

opencv_ios

opencv (face, eyes... tracking)
1
star
21

nghialv.github.com

my blog
HTML
1
star
22

flex-bison-cpp

a simple example of flex, bison
C++
1
star
23

tomojisho

a facebook game which looks like a dictionary for your friends. Through this game, you can review the information of your friends
PHP
1
star
24

rubyss

ruby shell script
Ruby
1
star