Want to get the item based on my indexpath rxcollectionviewdatasource
Problem:
I want to get the item from rxcollectionviewdatasource from multiple sections with multiple items.
Solution:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if let item = try? dataSource.model(at: indexPath) as? MyItem {
switch item {
case .model1(_):
return CGSize.zero
case . model2(info: let info):
return CGSize(width: 320, height: 100)
case . model3(info: _):
return CGSize(width: 320, height: 100)
case . model4(info: _):
return CGSize(width: 320, height: 100)
}
}
return CGSize.zero
}
ViewModel:
typealias SectionOfSearch = SectionModel<CollViewSearchSec
enum CollViewSearchSection {
case model1
case model2
case model3
case model4
}
enum SearchCollViewItem {
case model1(info: String)
case model2(info: Int)
case model3(info: Int)
case model4(info: String)
}
Comments
Post a Comment