Created
January 27, 2016 15:55
-
-
Save rayfix/00bc4fba3912aa20cd2c to your computer and use it in GitHub Desktop.
Trying to make a func visible to ObjC via protocol extension
This file contains 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
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