Last year massive improvements like diffable data source and compositional layout were pushed to UICollectionView
. UICollectionView
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 UICollectionViewListCofiguration
, UICollectionView
has become even more powerful and more customisable to use.
When paired with UICollectionViewListCell
, UICollectionView
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.
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:
The collection view’s sections are modelled using an enum
Section:
In the view controller ContactsViewController, create three properties — a view model, that contains the data, a UICollectionView
and a UICollectionViewDataSource
to render the data.
#uitableview #uicollectionview #ios #ios-14