UICollectionViewDiffableDataSource changes in Xcode 13

I am using the following codebase in Xcode 12 and it was working fine but in Xcode 13 it is giving compiling error. Please help.


    

    typealias DataSource = UICollectionViewDiffableDataSource<Section, Issues>

    @available(iOS 13.0, *)

    typealias DataSourceSnapshot = NSDiffableDataSourceSnapshot<Section, Issues>

    

    @available(iOS 13.0, *)

    private(set) lazy var dataSouurce = DataSource()

    @available(iOS 13.0, *)

    private(set) lazy var datasourceSnapshot = DataSourceSnapshot()

This codebase is giving me following error in variable dataSouurce declaration

Missing arguments for parameters 'collectionView', 'cellProvider' in call

Any help will be much appreciated.

Answered by surbhi_Magplus in 694055022

It was solved by passing the value using a function as per the apple documentation instead of variable declaration.

The function need to be called in viewdidload.

As far as I check the doc of UICollectionViewDiffableDataSource, it did not have an initializer init() even in iOS 14 SDK (Xcode 12). So, your code was using some undocumented feature and unfortunately it seemingly was working fine by luck. You may need to modify the initializer of dataSource properly.

Thanks for the quick answer. Can you please help me how can I create a class variable for it. So I can use it in multiple functions.

@surbhi_Magplus, sorry but you are not showing enough code to show something. Please show enough code which explains how you use it in multiple functions.

Thanks a lot I was able to get it solved using the hint provided by you.

Accepted Answer

It was solved by passing the value using a function as per the apple documentation instead of variable declaration.

The function need to be called in viewdidload.

UICollectionViewDiffableDataSource changes in Xcode 13
 
 
Q