Если вы хотите распознать, какой вид коллекции будет затронут методом sizeForItemAt
, вы можете просто использовать оператор ===
для этого.
Пример:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if collectionView === firstCollectionView {
// here it should returns the desired size
return CGSize(width: ..., height: ...)
}
// here it should returns the default size
return CGSize(width: ..., height: ...)
}
Или (более короткая версия):
return collectionView === firstCollectionView ? CGSize(width: ..., height: ...) : CGSize(width: ..., height: ...)