Skip to content

Instantly share code, notes, and snippets.

@noppefoxwolf
Created October 5, 2018 05:17
Show Gist options
  • Save noppefoxwolf/2a27ffcac0a2b6ceea3ffd1b2f6c3016 to your computer and use it in GitHub Desktop.
Save noppefoxwolf/2a27ffcac0a2b6ceea3ffd1b2f6c3016 to your computer and use it in GitHub Desktop.
Not implementable delegate in protocol extension.
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController, Interface {
lazy var tap = UITapGestureRecognizer(target: self, action: #selector(tapped))
override func viewDidLoad() {
super.viewDidLoad()
tap.delegate = self
view.addGestureRecognizer(tap)
}
@objc private func tapped(_ sender: UITapGestureRecognizer) {
print("hoge")
}
}
protocol Interface: UIGestureRecognizerDelegate {
func setup()
}
extension Interface where Self: MyViewController {
func setup() {
tap.delegate = self
}
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
return false
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment