Swiftpack.co -  lucamegh/Lists as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
lucamegh/Lists
Reusable generic list view controller.
.package(url: "https://github.com/lucamegh/Lists.git", from: "1.0.0")

Lists 🧻

Tired of configuring table views and collection views, confirming to delegates and data sources? Introducing Lists, a reusable generic list view controller built on top of UICollectionViewController.

Installation

Lists is distributed using Swift Package Manager. To install it into a project, simply add it as a dependency within your Package.swift manifest:

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/lucamegh/Lists", from: "1.0.0")
    ],
    ...
)

Usage

ListViewController(cellType: ArticleCell.self, items: articles) { cell, article in
    cell.viewModel = ArticleViewModel(article: article)
}

That's really it, but it doesn't stop there. You can optionally customize list view controllers by providing a custom UICollectionViewLayout.

ListViewController(layout: ArticleGridLayout(), cellType: ArticleCell.self, items: articles) { cell, article in
    cell.viewModel = ArticleViewModel(article: article)
}

Let's see how to dequeue different cell types:

enum Post {

    case text(TextPost)
    
    case image(ImagePost)
}

ListViewController(items: posts) { dequeue, indexPath, post in
    switch post {
        case .text(let post):
            let cell = dequeue(TextPostCell.self, for: indexPath)
            cell.viewModel = TextPostViewModel(post: post)
            return cell
        case .image(let post):
            let cell = dequeue(ImagePostCell.self, for: indexPath)
            cell.viewModel = ImagePostViewModel(post: post)
            return cell
    }
}

Thanks to DequeueAction there's no need to preregister your cells. You just have to dequeue them.

You can also create list view controllers with a publisher that emits an array of items. ListViewController will do an animated refresh as soon as new items are emitted.

let recipes = cookbook.recipes().replaceError(with: []).eraseToAnyPublisher()

ListViewController(cellType: RecipeCell.self, items: recipes) { cell, recipe in
    cell.configure(with: recipe)
}

GitHub

link
Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Lists 1.0.0
2 weeks ago

The first release of Lists.

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