Created
December 17, 2017 22:35
-
-
Save dkarbayev/80583019503e37c2e8cb83e601d84001 to your computer and use it in GitHub Desktop.
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
// | |
// ViewController.swift | |
// | |
import UIKit | |
public protocol Tapable {} | |
extension Tapable where Self: AnyObject { | |
public func tap(_ block: (Self) -> Void) -> Self { | |
block(self) | |
return self | |
} | |
} | |
extension NSObject: Tapable {} | |
class ViewController: UIViewController { | |
let table = UITableView().tap { | |
$0.backgroundColor = .black | |
$0.separatorStyle = .none | |
$0.rowHeight = 160 | |
} | |
override func loadView() { | |
super.loadView() | |
self.view.addSubview(self.table) | |
self.table.translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
self.table.topAnchor.constraint(equalTo: self.view.topAnchor), | |
self.table.leftAnchor.constraint(equalTo: self.view.leftAnchor), | |
self.table.rightAnchor.constraint(equalTo: self.view.rightAnchor), | |
self.table.bottomAnchor.constraint(equalTo: self.view.bottomAnchor) | |
]) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
print(#function, table.backgroundColor.debugDescription) | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
print(#function, table.backgroundColor.debugDescription) | |
} | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
print(#function, table.backgroundColor.debugDescription) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment