Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // traits
- protocol TableViewUpdating {
- func update(at: IndexPath)
- }
- extension TableViewUpdating {
- func update(at indexPath: IndexPath) {
- // default implementation
- }
- }
- protocol TableViewDeleting {
- func delete(at: IndexPath)
- }
- extension TableViewDeleting {
- func delete(at indexPath: IndexPath) {
- // default implementation
- }
- }
- // classes
- class DataSourceOne: UITableViewDataSource, TableViewUpdating, TableViewDeleting {
- }
- class DataSourceTwo: UITableViewDataSource, TableViewUpdating {
- }
- // test
- let one = DataSourceOne()
- one.update(at: IndexPath(item: 0, section: 0))
- one.delete(at: IndexPath(item: 0, section: 0))
- let two = DataSourceTwo()
- two.update(at: IndexPath(item: 0, section: 0))
- // 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