Using a Data Source | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5429927-beginning-collection-views/lessons/12

I tried using a UICollectionViewDiffableDataSource at first to practice more with it. However, my app crashed when updating the NSDiffableDataSourceSnapshot given that there are duplicates in the emojis.

Is this expected of diffable data sources? It doesn’t seem too safe to me that a data source can crash an app by just updating it with a duplicated values.

@samyanez94 Thanks very much for your question!

No, this is not expected of NSDiffableDataSources. Duplicates should not be a reason alone to have a crash. What was the error message that you received? Is this with your own project?

@syedfa Thanks for replying so quickly.

This is the error message: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Fatal: supplied identifiers are not unique.' and this was in the sample app.

I wondered why the identifiers were not unique so then I looked at the emoji data and noticed that two emojis were duplicated. I also noticed that the app was crashing in the appendItems(_:toSection:) method of the NSDiffableDataSourceSnapshot. After manually removing the duplicates, the crash was gone.

My guess is that UICollectionViewDiffableDataSource might not be able to handle collisions when two identifiers have the same hash values.

1 Like

This is indeed the right answer and is definitely a bug in the sample code. I’ll get the starter files updated

1 Like

I thought this video series was for the “old-school” method. However, this is using libraries from the iOS 13 SDK. That’s the opposite of old-school.

So sorry for the previous accusation, DiffableDataSource was removed. However, I jumped to the conclusion because the starter project requires XCode 11 which is equivalent to solely targeting iOS 13 devices in an “old-school” project. Don’t mean to complain, it just takes work around to truly make this project “old-school”.

1 Like