Created
September 11, 2018 08:07
-
-
Save ShoMasegi/b7ae7371becb7c08f8f91337e7d36f3c to your computer and use it in GitHub Desktop.
hatena_uitalbeview_register
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
extension UITableView { | |
func register<T: UITableViewCell>(_: T.Type) where T: Reusable { | |
register(T.self, forCellReuseIdentifier: T.reuseIdentifier) | |
} | |
func dequeueReusableCell<T: UITableViewCell>(for indexPath: IndexPath) -> T where T: Reusable { | |
guard let cell = dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as? T else { | |
fatalError("Could not dequeue cell with identifier: \(T.reuseIdentifier)") | |
} | |
return cell | |
} | |
func registerReusableHeaderFooterView<T: UITableViewHeaderFooterView>(_: T.Type) where T: Reusable { | |
register(T.self, forHeaderFooterViewReuseIdentifier: T.reuseIdentifier) | |
} | |
func dequeueReusableHeaderFooterView<T: UITableViewHeaderFooterView>() -> T where T: Reusable { | |
guard let view = dequeueReusableHeaderFooterView(withIdentifier: T.reuseIdentifier) as? T else { | |
fatalError("Could not dequeue headerfooter view with identifier: \(T.reuseIdentifier)") | |
} | |
return view | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment