Skip to content

Instantly share code, notes, and snippets.

@dkarbayev
Created December 17, 2017 22:35
Show Gist options
  • Save dkarbayev/80583019503e37c2e8cb83e601d84001 to your computer and use it in GitHub Desktop.
Save dkarbayev/80583019503e37c2e8cb83e601d84001 to your computer and use it in GitHub Desktop.
//
// 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