Skip to content

Instantly share code, notes, and snippets.

@ConorBrady
Last active April 25, 2017 17:06
Show Gist options
  • Save ConorBrady/ae9bf5528ef74346d330bda2366ce898 to your computer and use it in GitHub Desktop.
Save ConorBrady/ae9bf5528ef74346d330bda2366ce898 to your computer and use it in GitHub Desktop.
@objc protocol ViewDelegate {
func pressedButton()
}
class View: UIView {
let button = UIButton()
.stylePrimary(fontSize: 14)
.layout(width: 50, height: 30)
init() {
super.init(frame: .zero)
layout(center: button)
}
weak var delegate: ViewDelegate? = nil { didSet {
button.addTarget(delegate,
action: #selector(ViewDelegate.pressedButton),
for: .touchUpInside
)
} }
}
class ViewController: UIViewController, ViewDelegate {
init() { super.init(nibName: nil, bundle: nil) }
override func loadView() {
view = View() <== { $0.delegate = self }
}
func pressedButton() { /* react to button press */ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment