Guest User

Untitled

a guest
Jun 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // traits
  2.  
  3. protocol TableViewUpdating {
  4. func update(at: IndexPath)
  5. }
  6.  
  7. extension TableViewUpdating {
  8. func update(at indexPath: IndexPath) {
  9. // default implementation
  10. }
  11. }
  12.  
  13. protocol TableViewDeleting {
  14. func delete(at: IndexPath)
  15. }
  16.  
  17. extension TableViewDeleting {
  18. func delete(at indexPath: IndexPath) {
  19. // default implementation
  20. }
  21. }
  22.  
  23.  
  24. // classes
  25.  
  26. class DataSourceOne: UITableViewDataSource, TableViewUpdating, TableViewDeleting {
  27.  
  28. }
  29.  
  30. class DataSourceTwo: UITableViewDataSource, TableViewUpdating {
  31.  
  32. }
  33.  
  34.  
  35. // test
  36.  
  37. let one = DataSourceOne()
  38.  
  39. one.update(at: IndexPath(item: 0, section: 0))
  40. one.delete(at: IndexPath(item: 0, section: 0))
  41.  
  42. let two = DataSourceTwo()
  43. two.update(at: IndexPath(item: 0, section: 0))
  44. // two.delete(at: IndexPath(item: 0, section: 0)) => error: value of type 'DataSourceTwo' has no member 'delete'
Add Comment
Please, Sign In to add comment