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.6
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.
⭐️ 1
🕓 1 year ago
iOS
.package(url: "https://github.com/MobileUpLLC/ListController.git", from: "1.0.6")

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: 1
Last commit: 41 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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