Created
August 17, 2017 08:26
-
-
Save Dimillian/baca6f42d120015eed83e7f479c2a19c 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
public protocol Dequeueable { | |
static func id() -> String | |
static func hasNib() -> Bool | |
} | |
public extension UITableView { | |
func getCell<T: Dequeueable>(forType: T.Type) -> T? { | |
return dequeueReusableCell(withIdentifier: T.id()) as? T | |
} | |
func registerCell(withType cType: Dequeueable.Type) { | |
registerCells(withTypes: [cType]) | |
} | |
func registerCells(withTypes cType: [Dequeueable.Type]) { | |
for ty in cType { | |
if ty.hasNib() { | |
register(UINib(nibName: ty.id(), bundle: Bundle.main), forCellReuseIdentifier: ty.id()) | |
} else { | |
if let t = ty as? AnyClass { | |
register(t, forCellReuseIdentifier: ty.id()) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment