Created
April 2, 2019 10:51
-
-
Save JayachandraA/1a4d90035b0a95ba0bdd870579f7737d to your computer and use it in GitHub Desktop.
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
protocol Reusable { | |
static var reuseIdentifier: String {get} | |
} | |
extension Reusable { | |
static var reuseIdentifier: String { | |
return String(describing: self) | |
} | |
} | |
protocol NibLoader: class { | |
static var nib: UINib {get} | |
} | |
extension NibLoader { | |
static var nib: UINib { | |
return UINib(nibName: String(describing: self), bundle: Bundle(for: self)) | |
} | |
} | |
typealias NibReusable = Reusable & NibLoader | |
extension UITableView { | |
final func register<T: UITableViewCell>(cell: T.Type) where T: NibReusable { | |
self.register(cell.nib, forCellReuseIdentifier: cell.reuseIdentifier) | |
} | |
final func register<T: UITableViewCell>(cell: T.Type) where T: Reusable { | |
self.register(cell.self, forCellReuseIdentifier: cell.reuseIdentifier) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment