Created
June 20, 2018 19:04
-
-
Save jayrhynas/64acf5853d928957d6d93eccfa018713 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
// 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' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment