Swiftpack.co - MobileUpLLC/ListController as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by MobileUpLLC.
MobileUpLLC/ListController 1.0.5
Provides an abstraction layer to deal with listable data. It's a simpler and faster way to build table views on top of this than from scratch.
⭐️ 0
🕓 46 weeks ago
iOS
.package(url: "https://github.com/MobileUpLLC/ListController.git", from: "1.0.5")

ListController

Platform iOS Language: Swift 5 CocoaPods compatible SwiftPM compatible License: MIT

Provides an abstraction layer to deal with listable data. It's a simpler and faster way to build table views on top of this than from scratch.

Usage

1. Setup models and reusable views

1.1 Model setup

Item for cells must adopt Hashable protocol.

1.2 Cells setup

Table view cell should conform to Configurable protocol in order to receive cell item for setup.

extension Cell: Configurable {

    public func setup(with item: User) {

        textLabel?.text = item.name
    }
}

Sometimes you need to set delegate for cell, header or footer. For that purpose table adapter has sender property, which will be passed to configurable view, that adopts SenderConfigurable protocol.

extension Cell: SenderConfigurable {

    func setup(with item: Item, sender: ViewController) {

        textLabel?.text = object.name
        delegate = sender
    }
}

2. Use TableController as parent class

You must provide tableView property.

class ExamplesViewController: TableController<Int, Example> {

    override var tableView: UITableView { examplesTableView }
    
    private let examplesTableView = UITableView(frame: .zero, style: .grouped)
    private let items: [Example] = [ ... ]

    override func viewDidLoad() {
        super.viewDidLoad()

        // Setup table
        view.addSubview(tableView)
        tableView.register(ExampleCell.self, forCellReuseIdentifier: defaultCellReuseIdentifier)

        apply(items: items)
    }
    
    func apply(items: [RowItem], animated: Bool = false) {
        var snapshot = snapshot

        snapshot.deleteAllItems()
        snapshot.appendSections([0])
        snapshot.appendItems(items, toSection: 0)

        apply(snapshot, animating: animated)
    }
}

Requirements

  • Swift 5.1+
  • iOS 13.0+

GitHub

link
Stars: 0
Last commit: 4 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics