Created
November 14, 2017 13:13
-
-
Save VojtaStavik/700f9e925cd52058fac6eec5c2f3804b to your computer and use it in GitHub Desktop.
Code from the blog post about namespacing UITableView API. See http://vojtastavik.com/2017/11/14/namespace-all-the-things/
This file contains 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
import UIKit | |
enum UIKit { // UIKit namespace simulation | |
enum Table { // The new "root" namespace for UITableView | |
typealias View = UITableView | |
typealias ViewController = UITableViewController | |
typealias Cell = UITableViewCell | |
} | |
} | |
// If there wouldn't be a type named 'Table' in the current module, | |
// we could referent to 'UIKit.Table' by a simple 'Table'. | |
typealias Table = UIKit.Table | |
extension UIKit.Table { | |
typealias DataSource = UITableViewDataSource | |
typealias Delegate = UITableViewDelegate | |
} | |
class MyClass { } | |
extension MyClass: Table.DataSource { | |
func tableView(_ tableView: Table.View, cellForRowAt indexPath: IndexPath) -> Table.Cell { | |
} | |
} | |
class MyTableView: Table.View { } | |
class MyTableViewController: Table.ViewController { } | |
// You can refer to the type by its full namespace hierarchy, too. | |
class MyTableViewCell: UIKit.Table.Cell { } | |
extension UIKit.Table.Cell { | |
typealias Style = UITableViewCellStyle | |
typealias SeparatorStyle = UITableViewCellSeparatorStyle | |
typealias SelectionStyle = UITableViewCellSelectionStyle | |
} | |
let cellStyle: Table.Cell.Style = .default | |
let separatorStyle: Table.Cell.SeparatorStyle = .singleLine | |
let selectionStyle: Table.Cell.SelectionStyle = .blue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment