Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. protocol SourceType: UITableViewDataSource {
  2. associatedtype Element
  3. var dataObject: Element { get set }
  4. }
  5.  
  6. class DataSource<T: DataType>: NSObject, SourceType {
  7. typealias Element = T
  8. var dataObject: Element
  9.  
  10. init(dataObject: Element) {
  11. self.dataObject = dataObject
  12. }
  13.  
  14. @objc func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  15. return dataObject.numberOfItems
  16. }
  17.  
  18. @objc func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  19. fatalError("this method must be override")
  20. }
  21. }
  22.  
  23. protocol DataType {
  24. var numberOfItems: Int { get }
  25. }
  26.  
  27. final class CustomDatasource: DataSource<List> {
  28.  
  29. override init(dataObject: List) {
  30. super.init(dataObject: dataObject)
  31. }
  32.  
  33. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  34. return UITableViewCell()
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement