Skip to content

Instantly share code, notes, and snippets.

@iranjith4
Last active November 23, 2018 09:11
Show Gist options
  • Save iranjith4/c3adc9821e520b06fb278f6b63eae606 to your computer and use it in GitHub Desktop.
Save iranjith4/c3adc9821e520b06fb278f6b63eae606 to your computer and use it in GitHub Desktop.
reusableview-register-declaration
//CollectionView
extension UICollectionView {
func register<T: UICollectionViewCell>(_: T.Type) where T: ReusableView {
register(T.self, forCellWithReuseIdentifier: T.defaultReuseIdentifier)
}
func register<T: UICollectionViewCell>(_: T.Type) where T: ReusableView, T: NibLoadableView {
let bundle = Bundle(for: T.self)
let nib = UINib(nibName: T.nibName, bundle: bundle)
register(nib, forCellWithReuseIdentifier: T.defaultReuseIdentifier)
}
}
//TableView
extension UITableView {
//Registering Cell
func register<T: UITableViewCell>(_: T.Type) where T: ReusableView {
register(T.self, forCellReuseIdentifier: T.defaultReuseIdentifier)
}
func register<T: UITableViewCell>(_: T.Type) where T: ReusableView, T: NibLoadableView {
let bundle = Bundle(for: T.self)
let nib = UINib(nibName: T.nibName, bundle: bundle)
register(nib, forCellReuseIdentifier: T.defaultReuseIdentifier)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment