Created
November 23, 2018 09:13
-
-
Save iranjith4/ad46abdd8d534865698da2813fcde096 to your computer and use it in GitHub Desktop.
reusableview-dequeue-declaration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Dequeue methods for UICollectionView | |
func dequeueReusableCell<T: UICollectionViewCell>(for indexPath: IndexPath) -> T where T: ReusableView { | |
guard let cell = dequeueReusableCell(withReuseIdentifier: T.defaultReuseIdentifier, for: indexPath) as? T else { | |
fatalError("Could not dequeue cell with identifier: \(T.defaultReuseIdentifier)") | |
} | |
return cell | |
} | |
func dequeueReusableSupplementaryView<T: UICollectionReusableView>(ofKind: String, indexPath: IndexPath) -> T where T: ReusableView { | |
guard let supplementaryView = dequeueReusableSupplementaryView(ofKind: ofKind, withReuseIdentifier: T.defaultReuseIdentifier, for: indexPath) as? T else { | |
fatalError("Could not dequeue supplementary view with identifier: \(T.defaultReuseIdentifier)") | |
} | |
return supplementaryView | |
} | |
//Dequeue methods for UITableView | |
func dequeueReusableCell<T: UITableViewCell>(for indexPath: IndexPath) -> T where T: ReusableView { | |
guard let cell = dequeueReusableCell(withIdentifier: T.defaultReuseIdentifier, for: indexPath) as? T else { | |
fatalError("Could not dequeue cell with identifier: \(T.defaultReuseIdentifier)") | |
} | |
return cell | |
} | |
func dequeueReusableHeaderFooterView<T: UITableViewHeaderFooterView>(_ : T.Type) -> T where T: ReusableView { | |
guard let headerFooter = dequeueReusableHeaderFooterView(withIdentifier: T.defaultReuseIdentifier) as? T else { | |
fatalError("Could not dequeue Header/Footer with identifier: \(T.defaultReuseIdentifier)") | |
} | |
return headerFooter | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment