Last active
November 23, 2018 09:11
-
-
Save iranjith4/c3adc9821e520b06fb278f6b63eae606 to your computer and use it in GitHub Desktop.
reusableview-register-declaration
This file contains hidden or 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
//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