Value of type UICollectionViewListCell has no member leadingSwipeActionsConfiguration / trailingSwipeActionsConfiguration

Apple introduced new APIs to add leading and trailing swipe configuration in Xcode 12 Beta. They were introduced in Lists in UICollectionView video at 11:38 mark. However, needless to say, they're no longer valid and that's the whole reason why this blog post.

Back in July when I was still working on Swift, I came across Apple's WWDC announcement about list view support in UICollectionView and wrote a sample project to demonstrate its capability. I also have a blog post if you're curious about it. Let's see what it broken and how I fixed it.

Where did I get the error?

Recently I upgraded to Xcode 12 GM and tried to run my 3-month-old code again. But it failed with following error,

Value of type 'UICollectionViewListCell' has no member 'leadingSwipeActionsConfiguration'

I was confounded. I knew for sure that worked in Beta and GM now screwed it up. I spent some some searching for solution online, but looks like very few people had similar problem or detailed solution wasn't available.

How did I find the solution and fixed it?

Since the problem surfaced while assigning value to property leadingSwipeActionsConfiguration on UICollectionViewCell, I decided to do cmd+shift+o and search for this word to see if it has been moved somewhere else. Fortunately, I found that the property was now expected to set up on UICollectionLayoutListConfiguration which I was already constructing in the code. Looks like if you are implementing list view with UICollectionView, you would be setting up this configuration somewhere in the code.

To summarize, this error started surfacing because Apple changed the way leadingSwipeActionsConfiguration is set up. In the Xcode 12 Beta version, it was set on the UICollectionViewCell as a leadingSwipeActionsConfiguration property. While on Xcode 12 GM, it was set on the UICollectionLayoutListConfiguration object as a leadingSwipeActionsConfigurationProvider property.

So I replaced this code,

cell.leadingSwipeActionsConfiguration = <leading_swipe_actions_configuration_provider>

With,


var configuration = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
...
...
configuration.leadingSwipeActionsConfigurationProvider = { (indexPath) -> UISwipeActionsConfiguration in
	return <leading_swipe_actions_configuration_provider>
}
....
...

And that's about it and it was working as good as Xcode 12 Beta!