/RKTableAdapter

Table Adapter with batch updater

Primary LanguageSwiftMIT LicenseMIT

RKTableAdapter

CI Status Cocoapods compatible docs Version Platform Swift Version License

Content

Requirements

  • iOS 9.0 and above
  • Swift 4.1

Documentations

Full documentation for the latest release is available here

Installation

RKTableAdapter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RKTableAdapter', '~> 0.1'

Usage TableViewAdapter with UITableView

Manual create/update ViewController

  • Create TableViewAdapter
// Create
let tableView: UITableView = UITableView()
lazy var tableAdapter = TableViewAdapter(tableView: self.tableView)
  • Setup callbacks if needed
private func setupTableAdapter() {
    // tableAdapter.callbacks...
    // tableAdapter.scrollViewCallbacks...
}
  • Configure content
private func configureTableAdapterContent() {
    let tableList = TableList()

    makeMySection(tableList)

    tableAdapter.reload(with: tableList)
}

private func makeMySection(_ list: TableList) {
    let section = list["mySection"]
    section.headerHeight = 30
    section.footerHeight = 40

    do {
        let viewModel = TableSwitchCellVM(title: "Autosave", isOn: true)
        vmAutosave.changeAction = autosaveStateChanged

        let switchRow = TableRowSwitch(viewModel: vmAutosave)
        section.append(row: switchRow)
    }

    do {
        let vm = MenuItemCellVM(title: "Share", action: share)
        section.append(row: TableRow<MenuItemCell>(id: "uniq id", viewModel: vm))
    }
}
  • Add actions
private lazy var share: TableCellVM.ActionType = { [weak self] userInfo in
    guard let sself = self else { return }

    // do smth...
}
  • Update viewDidLoad
override viewDidLoad() {
    super.viewDidLoad()

    setupTableAdapter()
    configureTableAdapterContent()
}

Usage CollectionViewAdapter with UICollectionView

Manual create/update ViewController

  • Create ColelctionViewAdapter
// Create
lazy var collectionViewFlow: UICollectionViewFlowLayout = {
        let flow = UICollectionViewFlowLayout()
        // configure flow layout
        return flow
    }()
    lazy var collectionView: UICollectionView = {
        let cv = UICollectionView(frame: .zero, collectionViewLayout: collectionViewFlow)
        // configure collection view
        return cv
    }()
lazy var collectionAdapter = CollectionViewAdapter(collectionView: collectionView)
  • Setup callbacks if needed
private func setupCollectionAdapter() {
    // collectionAdapter.callbacks...
    // collectionAdapter.scrollViewCallbacks...
}
  • Configure content
private func configureCollectionAdapterContent() {
    let collectionList = CollectionList()
    
    makeTestSection(collectionList)

    collectionAdapter.reload(with: collectionList)
}

private func makeTestSection(_ list: CollectionList) {
    let section = list[SectionIds.diary.rawValue]
    
    do {
        // let vm = <#Collection Cell VM#>
        // vm.action = collectionCellAction
        // section.append(row: TableRow<<#Collection Cell Class#>>(id: "uniq id", viewModel: vm))
    }
}
  • Add actions
private lazy var collectionCellAction: CollectionCellVM.ActionType = { [weak self] _ in
    guard let sself = self else { return }
    
    print("cell taped")
}
  • Update viewDidLoad
override viewDidLoad() {
    super.viewDidLoad()

    setupCollectionAdapter()
    configureCollectionAdapterContent()
}

Templates

Generate Cells and ViewControllers from templates with Jessica

Download templates

jessica generator pull github.com/daskioff/jessica_templates rk_table_adapter

Fix output_paths in templates.yml for your project

Usage templates

Jessica Generator

jessica generator gen cell CELL_NAME

or

jessica generator gen cell_calc CELL_NAME

Author

DaskiOFF, waydeveloper@gmail.com

License

RKTableAdapter is available under the MIT license. See the LICENSE file for more info.

Последний раз проект собирался с версией Xcode указанной в файле .xcode-version (Подробнее)

Последний раз проект собирался с версией Swift указанной в файле .swift-version