The Blog

Implementing an infinite scrolling list with SwiftUI and Combine

Tons of apps that we build feature lists. Sometimes we build lists of settings, lists of todo items, lists of our favorite pictures, lists of tweets, and many other things. Some of these lists could scroll almost endlessly. Think of a Twitter timeline, a Facebook feed or a list of posts on Reddit. You might argue that knowing how to build a list that scrolls infinitely and fetches new content whenever a user reaches the end of the list is Read more…

Using multi-colored icons in iOS 14 with SF Symbols 2

This article covers beta technology and it’s up to date for Xcode 12 beta 1 Apple introduced SF Symbols in iOS 13. SF Symbols allow developers to easily integrate icons in their apps. The SF Symbols icons integrate really well with the default system font, and provide a consistent look throughout the system. In iOS 14, Apple added over 750 new icons to the SF Symbols library for developers to use in their apps. Additionally, Apple has expanded SF Symbols Read more…

How to change a UICollectionViewListCell’s separator inset

This article covers beta technology and it’s up to date for Xcode 12 beta 1 In WWDC2020’s session Lists in UICollectionView a slide is shown where a UICollectionViewListCell’s separator inset is updated by assigning a new leading anchor to separatorLayoutGuide.leadingAnchor. Unfortunately, this doesn’t work in when you try to do it. To set the separator inset for a UICollectionViewListCell you can update the leading anchor constraint by overriding updateConstraints in a UICollectionViewListCell subclass. Setting the anchor in init will cause Read more…

What’s new with UICollectionView in iOS 14

This article covers beta technology and it’s up to date for Xcode 12 beta 1 Last year, the team that works on UICollectionView shipped massive improvements like compositional layout and diffable data sources. This year, the team went all out and shipped even more amazing improvements to UICollectionView, making UITableView obsolete through the new UICollectionViewCompositionalLayout.list and UICollectionLayoutListConfiguration. This new list layout allows you to create collection views that look and function identical to UITableView. When paired with UICollectionViewListCell your collection Read more…

How to add a custom accessory to a UICollectionViewListCell?

This article covers beta technology and it’s up to date for Xcode 12 beta 1 Apple provides several accessory types that you can use to apply certain affordances to a UICollectionViewListCell. However, sometimes these options don’t suit your needs and you’re looking for something more customizable. To add a custom accessory to a list cell instead of a standard one, you use the .custom accessory type. The initializer for this accessory takes a UICellAccessory.CustomViewConfiguration that describes how your accessory should Read more…

How to add accessories to a UICollectionViewListCell?

This article covers beta technology and it’s up to date for Xcode 12 beta 1 In iOS 14 Apple added the ability for developers to create collection views that look and feel like table views, except they are far, far more powerful. To do this, Apple introduced a new UICollectionViewCell subclass called UICollectionViewListCell. This new cell class allows us to implement several tableviewcell-like principles, including accessories. Adding accessories to a cell is done by assigning an array of UICellAccessory items Read more…

How to add custom swipe actions to a UICollectionViewListCell?

This article covers beta technology and it’s up to date for Xcode 12 beta 1 In iOS 14 Apple added the ability for developers to create collection views that look and feel like table views, except they are far, far more powerful. To do this, Apple introduced a new UICollectionViewCell subclass called UICollectionViewListCell. This new cell class allows us to implement several tableviewcell-like principles, including swipe actions. You can add both leading and trailing swipe actions to a cell by Read more…

Configure collection view cells with UICollectionView.CellRegistration

This article covers beta technology and it’s up to date for Xcode 12 beta 1 In iOS 14 you can use the new UICollectionView.CellRegistration class to register and configure your UICollectionViewCell instances. So no more let cellIdentifier = "MyCell", no more collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) and best of all, you no longer need to cast the cell returned by dequeueReusableCell(withReuseIdentifier:for:) to your custom cell class. Adopting UICollectionView.CellRegistration in your project is surprisingly straightforward. For demo purposes I created the following Read more…

What’s the difference between @StateObject and @ObservedObject?

This article covers beta technology and it’s up to date for Xcode 12 beta 1 Views in SwiftUI are thrown away and recreated regularly. When this happens, the entire view struct is initialized all over again. Because of this, any values that you create in a SwiftUI view are reset to their default values unless you’ve marked these values using @State. This means that if you declare a view that creates its own @ObservedObject instance, that instance is replaced every Read more…

Using custom publishers to drive SwiftUI views

This article covers beta technology and it’s up to date for Xcode 12 beta 1 In SwiftUI, views can be driven by an @Published property that’s part of an ObservableObject. If you’ve used SwiftUI and @Published before, following code should look somewhat familiar to you: class DataSource: ObservableObject { @Published var names = [String]() } struct NamesList: View { @ObservedObject var dataSource: DataSource var body: some View { List(dataSource.names, id: \.self) { name in Text(name) } } } Whenever the Read more…