gitmyhub

CollectionKit

Swift ★ 4.5k updated 3y ago

Reimagining UICollectionView

Swift library for iOS that replaces UICollectionView with a simpler Provider pattern for building scrollable lists and grids, with automatic diff-based updates and composable multi-section layouts.

SwiftiOSsetup: easycomplexity 2/5

CollectionKit is a Swift library for iOS developers who build scrollable lists and grids of content inside their apps. iOS has a built-in component for this called UICollectionView, but developers often find it verbose and difficult to work with. CollectionKit offers a replacement that is designed to be simpler to set up, more composable, and better performing.

The core idea is a Provider pattern. Instead of implementing several delegate and data source methods scattered across a class, you describe your collection by assembling three objects: a data source that holds your items, a view source that describes how each item should appear on screen, and a size source that tells the layout how large each cell should be. You hand this bundle to the CollectionKit view, and it handles the rest. When your data changes, the framework automatically figures out what was added, removed, or moved, and updates only those parts of the screen.

Layout is handled by separate Layout objects that you can swap in or modify. The built-in options include a flow layout (items arranged left to right then wrapping to the next line), a waterfall layout (variable-height columns like a photo grid), and a row layout. Layouts can be transposed from vertical to horizontal or padded with insets by chaining modifier calls.

One of the more practical features is composition. You can take multiple independent providers, each with its own data, layout, and sizing rules, and combine them into a single scrollable view with separate sections. Updating one section does not require touching the others. The framework batches rapid data changes together so the screen only redraws once per layout cycle, which keeps scrolling smooth.

CollectionKit is installed through CocoaPods or Carthage. It requires iOS 8 and Swift 3 or later. The README is written for iOS developers and assumes familiarity with Swift and Xcode.

Where it fits