Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Code from the blog post about namespacing UITableView API. See http://vojtastavik.com/2017/11/14/namespace-all-the-things/
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