// // CollectionViewUtil.swift // HCQuanfangtong // // Created by Apple on 2021/12/29. // Copyright © 2021 Jyp. All rights reserved. // import UIKit extension UICollectionView{ func register(withType type : T.Type) where T: UICollectionViewCell{ self.register(UINib.loadNib(type), forCellWithReuseIdentifier: String(describing: type)) } func registerClass(withType type : T.Type) where T: UICollectionViewCell{ self.register(type, forCellWithReuseIdentifier: String(describing: type)) } func registerHeader(withType type : T.Type) where T: UICollectionReusableView{ self.register(UINib.loadNib(type), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: type)) } func registerHeaderClass(withType type : T.Type) where T: UICollectionReusableView{ self.register(type, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: type)) } func registerFooter(withType type : T.Type) where T: UICollectionReusableView{ self.register(UINib.loadNib(type), forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: String(describing: type)) } func registerFooterClass(withType type : T.Type) where T: UICollectionReusableView{ self.register(type, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: String(describing: type)) } func dequeueReusableCell(withType type : T.Type,for indexPath : IndexPath) -> T{ return self.dequeueReusableCell(withReuseIdentifier: String(describing: type), for:indexPath) as! T } func dequeueReusableSupplementaryHeaderView(withType type : T.Type,for indexPath : IndexPath) -> T{ return self.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: String(describing: type), for: indexPath) as! T } func dequeueReusableSupplementaryFooterView(withType type : T.Type,for indexPath : IndexPath) -> T{ return self.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: String(describing: type), for: indexPath) as! T } }