Diffable datasource and how to add new items / use snapshots properly

First question: I'd like to get clarification on what code I have to write to add a new item to a UICollectionView.

So far, I have managed to seed my datasource with some sample data, which correctly appears in the collectionView.

snapshot.appendSections(sections) //  assume there is only 1 section.
snapshot.appendItems(["addBoat"], toSection: .Boat)// placeholder for an add button
snapshot.appendItems(backingStore.BoatIdentifiers(), toSection: .Boats)// add the boats in the backing store.
 dataSource.apply(snapshot, animatingDifferences: false)

After the user enters the necessary data for a new boat, my code creates a new item instance (a struct).

The sample project DiffableDataSourceSample README states:

While a diffable data source can determine the changes between its current snapshot and a new one, it doesn't monitor the data collection for changes. Instead, it's the responsibility of the app to detect data changes and tell the diffable data source about those changes, by applying a new snapshot.

So does that really mean that when I add one new item, I have to 1) add it to my backing store, and then 2) create a new snapshot with all the data in my backing store so that I can 3) apply that to the dataSource? Intuitively, if my backing store has a couple thousand items, step 2 feels it could be very costly.

I was expecting that I could just append the new item to the existing snapshot (the one I created when seeding the data). But that means I have to keep the snapshot alive (and pass it around viewControllers). Something like this:

snapshot.appendItems(newBoat.id, toSection: .Boats)

Second, related question: I need to check that a new item doesn't already exist. Do I need to check in the existing snapshot? Like this:

if let index = snapshot.indexOfItem(newBoat.id) { 
... // boat is duplicate, don't allow adding it. 
}

Or do I check only in my backing store, and then do steps 1 2 and 3 above?

Thanks for any help.

I made a typo. the second line of code reads "snapshot.appendItems([...] toSectionL .Boat) Should read .Boats

Diffable datasource and how to add new items / use snapshots properly
 
 
Q