Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created January 27, 2016 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayfix/00bc4fba3912aa20cd2c to your computer and use it in GitHub Desktop.
Save rayfix/00bc4fba3912aa20cd2c to your computer and use it in GitHub Desktop.
Trying to make a func visible to ObjC via protocol extension
import UIKit
protocol Tapper: class {
func install()
func foo()
}
extension Tapper where Self: UIViewController {
func install() {
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "foo"))
}
// CRASH
// This doesn't get found by the tap gesture. Though it satisfies the protocol.
func foo() {
print("hello!")
}
}
class ViewController: UIViewController, Tapper {
// Defining foo here does get found.
override func viewDidLoad() {
super.viewDidLoad()
install()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment