Last year massive improvements like diffable data source and compositional layout were pushed to UICollectionViewUICollectionView didn’t exactly make its way into SwiftUI during this year’s WWDC, but that didn’t stop UICollectionView from receiving some powerful new updates. With the introduction of UICollectionViewCompositionalLayout.list and UICollectionViewListCofigurationUICollectionView has become even more powerful and more customisable to use.

When paired with UICollectionViewListCellUICollectionView now support features that used to only be available to UITableView only. For instance, now you can now add swipe actions and set its accessories on a cell like a disclosure indicator.

In the next few sections, we’ll see how one can construct layouts and cells in UICollectionView in the new iOS 14.

Setting Things Up

Let’s say we are working on a view to render a list of contacts. The contacts that will be displayed in the list are modelled as struct with three properties:

Image for post

The collection view’s sections are modelled using an enum Section:

Image for post

In the view controller ContactsViewController, create three properties — a view model, that contains the data, a UICollectionView and a UICollectionViewDataSourceto render the data.

Image for post

#uitableview #uicollectionview #ios #ios-14

Creating Lists with UICollectionView in iOS 14
5.20 GEEK