I just want to provide a solution that I've found for our use case.
We had the following:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: someCellId,
for: indexPath
) as! SomeCollectionViewCell
// some logic
return cell
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: someCellId,
for: indexPath
) as! SomeCollectionViewCell
// some more logic
}
I have changed the above code to the below, which fixed the crash.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: someCellId,
for: indexPath
) as! SomeCollectionViewCell
// some logic
return cell
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as? SomeCollectionViewCell
// some more logic
}
As you can see, we were using the dequeueReusableCell function twice, which caused the crash.
Using it only once fixed it for us.