• Stars
    star
    246
  • Rank 164,726 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 9 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 collectionview manager

Sapporo

Language CocoaPods [Carthage compatible] (https://github.com/Carthage/Carthage) License Issues

cellmodel-driven collectionview manager

Features

  • Easy to manage your sections and cells (reset/insert/append/remove/update)
  • Don't have to write the code for UICollectionViewDelegate and UICollectionViewDataSource protocols
  • Don't need to care about cell identifier
  • Handle cell selection by trailing closure
  • Supports method chaining
  • Supports subscript
  • Complete example
Quick example
// viewController swift file

let sapporo = Sapporo(collectionView: self.collectionView)

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

let topSection = SASection()

sapporo
	.reset(topSection)
	.bump()

topSection
	.append(cellmodel)	// append a new cell model in datasource
	.bump()	// show the new cell in the collection view

topSection
	.remove(1...3)
	.bump()

topSection
	.move(fromIndex: 0, toIndex: 3)
	.bump()
// your cell swift file

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

	init(title: String, des: String, selectionHandler: (SACell) -> Void) {
		self.title = title
		self.des = des
		super.init(cellType: YourCell.self, selectionHandler: selectionHandler)
	}
}

class YourCell : SACell, SACellType {
	typealias CellModel = YourCellModel

	@IBOutlet weak var titleLabel: UILabel!

	override func configure() {
		super.configure()

		guard let cellmodel = cellmodel else {
			return
		}

		titleLabel.text = cellmodel.title
      	}
	}

Usage

  • Handling section
// retrieve a section or create a new section if it doesn't already exist
let section = sapporo[0]
	
// inserting
sapporo.insert(section, atIndex: 1)
	 .bump()

// moving
sapporo.move(fromIndex: 1, toIndex: 5)
	.bump()

// removing
sapporo.remove(index)
	.bump()

// remove all data
sapporo.reset()
	.bump()

// handing section index by enum
enum Section: Int, SASectionIndexType {
	case top
	case center
	case bottom

	static let count = 3
}

let topSection = sapporo[Section.Top]
  • Handling cell
// appending
sapporo[0]
	.append(cellmodel)	// append a cellmodel
	.bump()	// and bump to show the cell in the collection view

sapporo[TopSection]
	.append(cellmodels)	// append a list of cellmodels
	.bump()					

// by using section
let section = sapporo[Section.Top]
section
	.append(cellmodel)
	.bump()

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

section
	.insertBeforeLast(cellmodels)
	.bump()

// 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. moving
section
	.move(fromIndex: 5, toIndex: 1)
	.bump()

// 5. removing
section
	.remove(1)
	.bump()

section
	.remove(cellmodel)
	.bump()

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

section
	.removeLast()
	.bump()

// updating cell
let cellmodel = section[1]
cellmodel.property = newData
cellmodel.bump()

// able to retrieve a cellmodel by indexpath
let cellmodel = sapporo[indexpath]
  • Registering cell, header, footer, reusable view
sapporo
	.registerCellByNib(CustomCell)
	.registerCell(SimpleCell)
	.registerSupplementaryViewByNib(HeaderView.self, kind: "SectionHeader")
  • Customizing layout

In case you want to customize the layout of collection view, just create a subclass of SALayout and call setLayout method to set the new layout instance.

class CustomLayout: SALayout {
	// the implementation for your layout
}

let layout = CustomLayout()
sapporo.setLayout(layout)

Installation

  • Using Carthage

    • Insert github nghialv/Sapporo to your Cartfile
    • Run carthage update
  • Using CocoaPods

    • Insert followings to your Podfile
     use_frameworks!
    
     target 'YOUR_TARGET_NAME' do
       pod 'Sapporo'
     end
    
    • Run pod install
  • Using submodule

Requirements

  • iOS 9.0+
  • Xcode 9+
  • Swift 4

License

Sapporo is released under the MIT License.

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

Hakuba

🌸 Cellmodel-driven tableview manager
Swift
474
star
4

Transporter

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

Net

Http Request wrapper written in Swift
Swift
302
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