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
class MyClass: UIView { | |
let tableView: UITableView | |
let textField: UITextField | |
let buttonOne: UIButton | |
let buttonTwo: UIButton | |
init() { | |
tableView = UITableView(frame: .zero, style: .plain) | |
tableView.backgroundColor = .clear |
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
class Foo { | |
var bar: String | |
init() { } | |
} | |
// Before | |
let foo = Foo() | |
foo.bar = "bar" | |
// After |
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
infix operator <== | |
@discardableResult | |
public func <== <T>(x: T, f: (T) -> ()) -> T { | |
f(x) | |
return x | |
} |
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
protocol HasModel { | |
associatedtype Model | |
var model: Model? { get set } | |
} | |
protocol HasHeight { | |
static var height: CGFloat { get } | |
} | |
extension UIView { |
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
@objc protocol ViewDelegate { | |
func pressedButton() | |
} | |
class View: UIView { | |
let button = UIButton() | |
.stylePrimary(fontSize: 14) | |
.layout(width: 50, height: 30) |
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
extension UIButton { | |
func stylePrimary(fontSize: CGFloat) -> UIButton { | |
// Apply styles e.g. round corners, border, font etc | |
setBackgroundImage(.init(with: .orange), for: .normal) | |
setBackgroundImage(.init(with: .darkOrange), for: .highlighted) | |
return self | |
} | |
} | |
let button = UIButton().stylePrimary(fontSize: 14) |
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
// With segues | |
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
switch segue.identifier { | |
case .some(“doTheThing”): | |
guard let vc = segue.destination as? ParameterizedViewController else { return } | |
vc.param = sender.param | |
} | |
} | |
// Without segues |
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
class TableViewController<Cell>: UITableViewController where Cell: UITableViewCell, Cell: HasModel, Cell: HasHeight { | |
let models: [Cell.Model] | |
let onSuccess: (Cell.Model, TableViewController<Cell>) -> () | |
init( | |
models: [Cell.Model], | |
style: UITableViewStyle, | |
onSuccess: @escaping (Cell.Model, TableViewController<Cell>) -> () | |
) { |
NewerOlder