Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import UIKit
  2.  
  3. protocol Actionable {
  4. func action()
  5. }
  6.  
  7. extension UIResponder: Actionable {
  8. func action() {
  9. next?.action()
  10. }
  11. }
  12.  
  13. class ViewModel: UIResponder {
  14. override func action() {
  15. print("action")
  16. }
  17. }
  18.  
  19. class MyView: UIView {
  20. func tapped() {
  21. next?.action()
  22. }
  23. }
  24.  
  25. class ViewController: UIViewController {
  26. let viewModel = ViewModel()
  27. let myView = MyView()
  28.  
  29. override var next: UIResponder? {
  30. return viewModel
  31. }
  32.  
  33. override func viewDidLoad() {
  34. super.viewDidLoad()
  35. view.addSubview(myView)
  36. }
  37. }
  38.  
  39. let controller = ViewController(nibName: nil, bundle: nil)
  40. _ = controller.view
  41. controller.myView.tapped()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement