I added a UIView to comply with the UIGestureRecognizerDelegate protocol
The following code compiles
let label = UILabel() let recognizer = UITapGestureRecognizer(target: label.self, action: Selector("tapGestureHandler:")) recognizer.delegate = label.self label.addGestureRecognizer(recognizer)
Now I'm trying to create a general subclass to create another subclass of UIView
class MyView<T:UIView> { init() { (T.self as T.Type).init(frame: CGRectZero) } func addGestureToView() { let recognizer = UITapGestureRecognizer(target: T.self, action: Selector("tapGestureHandler:"))
Strange thing for me: T.addGestureRecognizer expects a UIView, not a UIGestureRecognizer
Update
I want the return type MyView to be a subclass of UIView,
let view = MyView<UIView>()
// I want to use it this way
view.tintColor = UIColor.redColor()
// But I have to use this method
view.subview.tintColor = UIColor.redColor()
source share