xcode,  ios,  swift

UICollectionView terminating with uncaught exception of type NSException

ne of our views that contains a UICollectionView started crashing once in a while...

UICollectionView terminating with uncaught exception of type NSException

The problem:

One of our views that contains a UICollectionView started crashing once in a while with the following descriptive error:

libc++abi.dylib: terminating with uncaught exception of type NSException

Stack trace was not very helpful.

The solution:

Most of the uncaught exception in a collection view occur when it is being partially reloaded (insertItems, reloadItems, reloadSections, etc.) and its data-source is not what it expects to be.

In our case, we re-used the same collection view and did not run self.collectionView.reloadData() before each re-use so adding that line of code fixed the issue.

Subscribe to The infinite monkey theorem

Get the latest posts delivered right to your inbox