Skip to content

Commit

Permalink
Added new dequeue method to UITableView
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrommcarrasco committed Apr 8, 2019
1 parent d65044a commit ef68b7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sucrose.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.swift_version = "5.0"
s.name = "Sucrose"
s.version = "3.4.3"
s.version = "3.5.0"
s.summary = "🍬 Everyday sugar"
s.description = "Collection of handy methods & objects"

Expand Down
12 changes: 10 additions & 2 deletions Sucrose/Extensions/UITableView+Cell.swift
Expand Up @@ -26,9 +26,17 @@ public extension UITableView {
return cell
}

func dequeue<T: UITableViewHeaderFooterView>(_ type: T.Type) -> T {
func dequeue<T: UITableViewCell>(_ type: T.Type) -> T? {
guard let cell = self.dequeueReusableCell(withIdentifier: type.name) as? T else {
return nil
}

return cell
}

func dequeue<T: UITableViewHeaderFooterView>(_ type: T.Type) -> T? {
guard let view = self.dequeueReusableHeaderFooterView(withIdentifier: T.name) as? T else {
fatalError("Unable to dequeue \(T.name)")
return nil
}

return view
Expand Down

0 comments on commit ef68b7b

Please sign in to comment.