I have custom view, which contains UILabel and I add gesture recognizer to this label in init.
protocol CustomViewDelegate: class {
func customViewDidTapOnLabel(_ customView)
}
class CustomView: UIView {
lazy var label = UILabel()
weak var delegate: CustomViewDelegate?
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(label)
label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(labelTapped))
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc func labelTapped() {
delegate?.customViewDidTapOnLabel(self)
}
}
The question is, should I remove gesture recognizer in deinit? Does the label keep strong reference do UITapGestureRecognizer?