title: Invalid parameter not satisfying: initialSnapshot.numberOfSections == initialSections.count
body: <p>Working on a new project, our team decided to use <code>UICollectionViewDiffableDataSource</code> to handle our collection views. It works fine, but we're getting (infrequent) crashes logged via an online tool with the message <code>Invalid parameter not satisfying: initialSnapshot.numberOfSections == initialSections.count</code>. We can't seem to reproduce this locally.</p>
  <p>The crash occurs at the point where we update the data source with new data, specifically at <code>dataSource.apply(snapshot)</code>. We're unsure as to how this could happen, as the data is always created the same.</p>
  <p>Specifically, the unit working on this one view decided to forgo the creation of a section model and instead decided to use an <code>Int</code> as section identifiers, because they didn't want to use sections, just display items. That's one thing I hadn't seen before, but an <code>Int</code> satisfies the requirements for identifiers, so the code does compile correctly.</p>
  <p>Here is the code:</p>
  <p><strong>Collection View and Data Source creation</strong></p>
  <p>These variables are inside the class of a UIView which is programmatically created.</p>
  <pre><code>var collectionView = UICollectionView(frame: .zero, collectionViewLayout: createCollectionViewLayout())
  lazy var dataSource = UICollectionViewDiffableDataSource&lt;Int, URL&gt;(collectionView: collectionView, cellProvider: provideCell(_:indexPath:item:))
  </code></pre>
  <p><strong>Updating the Datasource</strong></p>
  <pre><code>func updateUI() {
      var snapshot = dataSource.snapshot()
      snapshot.deleteAllItems()
      snapshot.appendSections([0])
      
      if let urls = viewModel?.imageUrls {
          snapshot.appendItems(urls)
      }
  
      dataSource.apply(snapshot)
  }
  </code></pre>
  <p>In all (production) cases I have tested, <code>viewModel?.imageUrls</code> is empty on the first call, then contains items on the second call and all calls after that. The number of items usually doesn't change.</p>
  <p>I have thought about not using <code>dataSource.snapshot()</code> and instead creating a new one, then I also wouldn't have to call <code>deleteAllItems()</code> every time. But I don't want to just push this as the solution when I can't be sure whether this really fixes the issue.</p>
  <p>Has anyone encountered an issue like this before? Is it correct to use an <code>Int</code> as the section identifier? What could be other causes of the crash?</p>